话不多说直接上示例代码解释
1 -- 查看数据库 2 show database; 3 4 -- use命令选择数据库 5 use database \'db_name\'; 6 7 -- 查询数据库连接 8 show full processlist; 9 10 -- status查看mysql数据库的运行状态 11 -- 最大已用连接数 12 show status like \'%max_used_connections%\'; 13 14 -- 当前连接数 15 show status like \'%threads_connected%\'; 16 17 -- 表锁定 18 show status like \'%table_lock%\'; 19 20 -- 行锁定 21 show status like \'innodb_row_lock%\'; 22 23 -- 查询缓存情况 24 show status like \'%qcache%\'; 25 show variables like \'query_cache%\'; 26 show variables like \'%binlog%\'; 27 28 -- 由于客户没有正确关闭连接已经使连接死掉 已经放弃的连接数 29 show status like \'aborted_clients\'; 30 31 -- 最大连接数 32 show variables like \'%max_connections%\'; 33 34 -- 查询超时时间 35 show variables like \'%timeout%\'; 36 37 -- 查看是否开启日志 38 show variables like \'log_%\'; 39 40 -- 查看数据库下所有的表 41 show tables; 42 43 -- 查看表结构 OR DESC table_name 44 show columns from table_name; 45 desc table_name; 46 47 -- 查看表的状态 引擎,版本,索引等信息 48 show table status from youshi_boche360_ like "%table_name%"; 49 50 -- 查看表生成的DDL 51 show create table table_name; 52 53 -- 复制表的结构 54 create table1 table2 like table1; 55 56 -- 复制表数据 57 insert into table1 select * from table2;
小技巧:当多行命令输入的时候,发现错误后,可用 \c 结束
整理下可能会用到的一些其他命令
1 -- 查询数据后直接插入数据 2 insert into table2(`id`,`name`,`describe`) select `id`,`name`,`describe` from table1; 3 4 -- 机器授权 5 grant select on *.* to \'reader\'@\'%\' identified by \'123456\' with grant option flush privileges;