msql运维常用命令行

1单库统计数据:

select table_schema,sum(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 as mb from information_schema.tables group by table_schema;

 2导出所有库中所有单表的备份语句

mysql> select concat("mysqldump -uroot -p123456 ",table_schema," ",table_name," >/tmp/",table_schema,"_",table_name,".sql") from information_schema.tables into outfile '/tmp/bak1.sh';
Query OK, 287 rows affected (0.23 sec)

mysql> exit
Bye
[root@instance-r5y0pf5d ~]# sh /tmp/bak1.sh

 

[root@instance-r5y0pf5d /tmp]# rm -rf *.sql

 

 3常用show语句:

show databases;

查看所有数据库名

show tables;

查看当前库下的所有表名

show tables from world;

查看world数据库下的表名

show create database world;

查看world库的建库语句

SHOW CREATE TABLE city;

查看建表语句

SELECT user,host FROM mysql.user;

查询数据库中所有用户

show grants for 'tyjs09'@'%';

查看数据库中某个用户的权限

show charset;

查看字符集

show collation;

查看校对规则

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4查看默认存储引擎:

mysql> select @@default_storage_engine;
mysql> show variables like '%engine%';

 5默认存储引擎设置

会话级别(影响当前会话):
set default storage_engine=myisam;
全局级别(仅影响新会话)
set global default_storage_engine=myisam;
以上操作在服务区重启后失效,如要永久生效,需写入配置文件:
vim /etc/my.cnf
[mysqld]
default_storage_engine=myisam

 6查看每个表的存储引擎

mysql> show create table city\G; 
mysql> show table status like 'course'\G

 7查看整个库里的每张表的存储引擎

select table_schema,table_name,engine from information_schema.tables where table_schema not in ('sys','mysql','information_schema','performance_schemn');

 8修改一个表的存储引擎

create table tb1 (id int) engine=myisam;
show create table tb1
alter table tb1 engine=innodb;

 9表的碎片整理命令:

即是修改引擎的命令,又是碎片整理命令
alter table tb1 engine=innodb;

 10将所有表的innodb引擎替换为tokudb引擎:

#查看都支持哪些引擎:
mysql> show engines\G #将course表的引擎改为myisam mysql> alter table course engine=MyISAM; #查看表的引擎 mysql> show create table course\G #将表的所有引擎修改语句导出

select concat("alter table testku.",table_name," engine innodb;") from information_schema.tables where table_schema='testku' into outfile '/tmp/innodb.sql';

 

 

 

 

posted @ 2021-01-18 18:45  linuxTang  阅读(85)  评论(0)    收藏  举报