mysql常用命令

Mysql5.7修改密码
alter user root@'localhost' identified by 'Aa!123456';

查看mysql版本
mysql --help | grep Distrib

mysql查看表大小: information_schema下有tables这个表,里面记录了:
例如查看test_dsg下的test1:
select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables where table_schema='test_dsg' and table_name='test1';

查看权限:
Show grants for 'dsg'@'localhost'G

更改字段类型:
alter table pm_accident_build modify column build_id varchar(256);

查看数据库大小:
use information_schema;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES;
查看数据库容量
select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables
group by TABLE_SCHEMA
order by data_length desc;


select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='库名' and table_name='表名';

select round(sum(DATA_LENGTH+INDEX_LENGTH)/1024/1024/1024,2) "total_size/G" from information_schema.tables;

select table_schema as '数据库', sum(table_rows) as '记录数', sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)', sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)' from information_schema.tables group by table_schema order by sum(data_length) desc, sum(index_length) desc;

MySQL 下批量清空某个库下的所有表(库不要删除,保留空库

1)第一步(只需将下面的"库名"替换成实际操作中的库名即可)
select concat('drop table ',table_name,';') from information_schema.TABLES where table_schema='库名';
2)第二步
切换到这个库下,把第一步的执行结果导出,然后全部执行

查看schema下表的数据个数总和:
Select sum(table_rows) from tables where table_schema='ccs_pm';

如果想要密码设置简单点,方法如下:

set global validate_password_policy=0;
set global validate_password_length=4;

上述是把密码程度设置成最低级,密码长度设置成4(最小是4,不能再少了)

查看mysql本次启动后的运行时间(单位:秒)
show status like 'uptime';
查看select语句的执行数
show global status like 'com_select';
查看insert语句的执行数
show global status like 'com_insert';
查看update语句的执行数
show global status like 'com_update';
查看delete语句的执行数
show global status like 'com_delete';

原文地址:https://www.cnblogs.com/jiayan666/p/14283016.html