mysql常用命令


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表来查看


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章