收集整理,僅供個人參考學習。
查看連接數(shù)
show processlist; 也可以查information_schema.processlist表
查看定義/默認的參數(shù)
show variables like '%參數(shù)名字%';
取消用戶權(quán)限:
revoke SELECT, EXECUTE, SHOW VIEW ON `tsdp`.* from? 'tsdp_ro'@'10.58.%.%'? ;
更改參數(shù)
set session 參數(shù)名字=值;
set global 參數(shù)名字=值;
查看狀態(tài)值
show global status;
show status like '%參數(shù)名字%';
查看同步狀態(tài)
show slave status\G 做主從同步 change master to.....
創(chuàng)建用戶/賦予權(quán)限
create usertest@'111.111.111.111'identified by '123456';
grant all on clus.* totest@'111.111.111.111';
查看觸發(fā)器
use clus;
show triggers;
show create trigger triggername; 可以在information_schema.trigger差看
查看存儲過程
use clus;
show procedure status;
show create procedure procedurename;
查看event
use clus;
show events;
show create event eventname;
建庫
CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
添加字段
alter table tablename add column name varchar(10);
添加自增主鍵字段
alter table tablename add column `ID` int primary key auto_increment;
修改字段類型
alter table tablename modify column name varchar(10);
刪除字段
alter table tablename drop clumn name;
索引
alter table tablename add index index_name (字段);
alter table tablename drop index index_name;
create index index_name on tablename(字段);
drop index index_name on tablename;
主鍵
alter?table tablename addprimary?key (`ID`) auto_increment;
1.alter table tablename modify column `ID` int
2.alter?table tablename dropprimary?key (`ID`);
鎖庫備份
/usr/local/mysql/bin/mysqldump -uroot -p'vxxx' -h127.0.0.1 -P3306 --databases 庫名 --lock-all-tables --master-data > axx_20130607.sql 不鎖就去掉--lock-all-tables --master-data
錯誤鏈接過多,mysqld中斷主機所有請求,恢復可請求狀態(tài)
mysqladmin flush-hosts
查看用戶資源限制情況
select Host,User,Password,max_questions,max_updates,max_connections,max_user_connections from mysql.user;
轉(zhuǎn)換Myisam引擎到Innodb
alter table your_table_name engine='Innodb';
查看是否有使用Myisam引擎的表結(jié)構(gòu)
select * from information_schema.tables where TABLE_SCHEMA not in ('mysql','information_schema','performance_schema') and engine != 'InnoDB';
導出表結(jié)構(gòu)
mysqldump -u*** -p -d your_database_name > database_structure.sql
查看user權(quán)限
show grants for root@'127.0.0.1';
為一個用戶修改權(quán)限
UPDATEmysql.userSETGrant_priv='Y',Super_priv='Y'WHEREUser='root';
FLUSH PRIVILEGES;
mcluster限制檢查sql
SELECT DISTINCT
CONCAT(t.table_schema,'.',t.table_name) as tbl,
t.engine,
IF(ISNULL(c.constraint_name),'NOPK','') AS nopk,
IF(s.index_type = 'FULLTEXT','FULLTEXT','') as ftidx,
IF(s.index_type = 'SPATIAL','SPATIAL','') as gisidx
FROM information_schema.tables AS t
LEFT JOIN information_schema.key_column_usage AS c
ON (t.table_schema = c.constraint_schema AND t.table_name = c.table_name
AND c.constraint_name = 'PRIMARY')
LEFT JOIN information_schema.statistics AS s
ON (t.table_schema = s.table_schema AND t.table_name = s.table_name
AND s.index_type IN ('FULLTEXT','SPATIAL'))
WHERE t.table_schema NOT IN ('information_schema','performance_schema','mysql')
AND t.table_type = 'BASE TABLE'
AND (t.engine <> 'InnoDB' OR c.constraint_name IS NULL OR s.index_type IN ('FULLTEXT','SPATIAL'))
ORDER BY t.table_schema,t.table_name;
源數(shù)據(jù)庫mysql特性統(tǒng)計
select * from mysql.func;
select * from information_schema.ROUTINES where ROUTINE_SCHEMA = 'win4';
select * from mysql.event;
select * from information_schema.EVENTS where EVENT_SCHEMA = 'win4';
select * from mysql.proc;
select * from information_schema.VIEWS where TABLE_SCHEMA = 'win4';
select * from information_schema.TRIGGERS where TRIGGER_SCHEMA = 'win4';
select * from information_schema.tables where table_schema= 'win4' and engine != 'InnoDB';
select * from information_schema.STATISTICS where table_schema = 'win4' and INDEX_TYPE in ('FULLTEXT','SPATIAL');
select t.table_schema,t.TABLE_NAME,c.CONSTRAINT_TYPE from information_schema.tables t left join information_schema.TABLE_CONSTRAINTS c on t.TABLE_SCHEMA = c.TABLE_SCHEMA and t.TABLE_NAME = c.TABLE_NAME and c.CONSTRAINT_TYPE = 'PRIMARY KEY' where t.TABLE_SCHEMA = 'win4' and c.CONSTRAINT_TYPE is null;