1、查看存儲過程
select specific_name from mysql.proc;
show procedure status;
select `name` from mysql.proc where db='dbname' and type='procedure';
2、對於特殊關鍵字的表,要使用tab鍵處的單引號
show create table `union`;
3、show errors; show warnings;
4、轉化mysql的數據文件爲可讀類型
hexdump -C -v 數據文件>mysql.txt
5、查看錶、存儲過程的存儲、定義狀態、使用什麼存儲引擎
show table status like 'tablename';
show procedure status like 'procedurename';
6、查看ST數據庫中以C開頭的表名
select table_name from information_schema.tables where table_schema='ST' and table_name like 'C%';
select * from information_schema.tables where table_type='base table' and table_schema='databasename';
7、建立和表petlist結構相同的表
create table tt like petlist;
8、增加主鍵和外鍵
alter table t4 add CONSTRAINT pk_t4 PRIMARY KEY (id);
alter table t2 add constraint pk_fid foreign key t2(id) references t3(id);
9、查看最近一次查詢的開銷,他來自對於統計數據的估計,統計數據主要包含每個表或者索引的頁面數量
show status like 'last_query_cost'
10、general_log=on 生成一個主機名.log的文件,記錄了數據庫中的每次操作語句。
11、innodb_stats_on_metadata默認是開啓的,設置爲off的之後,就不會觸發索引統計
12、查看mysql innodb的版本
In the error log, it is printed during startup
show variables like 'innodb_version'\G;
select * from information_shcema.plugins;
select @@innodb_version;
13、表修復
mysqlcheck -r mysql proc
14、限制單個用戶連接數
grant all privileges on *.* to 'zjz'@'localhost' with grant option max_user_connections 20
-> max_connections_per_hour 100
-> max_queries_per_hour 1000
-> max_updates_per_hour 1000;
15、刷新緩衝區
(1). RESET QUERY CACHE;
(2). FLUSH TABLES;
16、mysql設置時區
set time_zone='+8:00';//表示北京時間,只對當前的窗口生效
可在配置文件中設置:default_time_zone
一般是和系統的時間保持一致的,如果不想使用系統的時間,可以設置上面的參數
default_time_zone=+8:00
17、vim /etc/resolv.conf(域名解析 nameserver 8.8.8.8)
18、查看mysql中兩個表的結構差異
select TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE ,COLUMN_KEY from information_schema.COLUMNS where TABLE_NAME='test' and TABLE_SCHEMA='test';
通過information_schema.columns表來查看