mysql常用操作

#导出数据库结构
mysqldump -uroot -h127.0.0.1 -P3306 -pxxxx --set-gtid-purged=OFF -BRE --events --triggers -d qfgn > qfgn_20190531.sql
#导出数据库
mysqldump -uroot -h127.0.0.1 -P3306 -pxxxx --set-gtid-purged=OFF -BRE --events --triggers qfgn > qfgn_20190531.sql
#导出全部应用数据库
time mysql -h${ip} -P${port} -uroot -pxxxx -e 'show databases;' | grep -Ev "Database|information_schema|mysql|performance_schema" | grep -v "^test$" | xargs mysqldump -uroot -pxxxx -h${ip} -P${port} --single-transaction --master-data=2 --flush-logs -BRE --set-gtid-purged=OFF --events > ./${pub_ip}_mysql.sql
#导出表数据 mysqldump -uroot -h127.0.0.1 -P3306 -pxxxx --set-gtid-purged=OFF qfgn qfgn_sys_menu > qfgn_sys_menu.sql
#导出表结构
mysqldump -uroot -h127.0.0.1 -P3306 -pxxxx --set-gtid-purged=OFF -d qfgn qfgn_sys_menu > qfgn_sys_menu.sql


#导入数据库
time mysql -h127.0.0.1 -P3336 -uroot -pxxxx < ./${pub_ip}_mysql.sql

#导入表数据
time mysql -h127.0.0.1 -P3336 -uroot -pxxxx qfgn < qfgn_sys_menu.sql

#导出指定条件的数据
mysqldump -uroot -h127.0.0.1 -P3306  -pxxxx 库名 表名 --where="id < 386" > menu_new_385.sql

 

查看mysql库大小,表大小,索引大小:

进入information_schema库
mysql> use information_schema;
查看所有库的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES;
查看指定库的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES where table_schema='jishi';
查看指定库的指定表的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES where table_schema='jishi' and table_name='a_ya';
查看指定库的索引大小
mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM TABLES  WHERE table_schema = 'jishi';
查看指定库的指定表的索引大小
mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM TABLES  WHERE table_schema = 'test' and table_name='a_yuser';
查看一个库中的情况...
mysql>  SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'test';

 

查询操作

按照log_time字段排序:
select * from log_science order by log_time;

限制显示输出条数
select * from log_science order by log_time desc limit 10;

 

posted @ 2019-05-31 11:58  chenjianwen  阅读(356)  评论(0编辑  收藏  举报