工作中常用命令参考,收集如下:
查询表大小:
select table_name, data_length from information_schema.tables where table_schema='testTable';
查询表行数(基于information_schema)
SELECT t.TABLE_SCHEMA,t.TABLE_NAME,t.TABLE_ROWS,t.CREATE_TIME,t.UPDATE_TIME FROM information_schema.TABLES t WHERE t.TABLE_NAME='history' AND t.TABLE_SCHEMA='zabbix' ORDER BY t.CREATE_TIME DESC,t.UPDATE_TIME DESC;
查询所有表行数降序(基于information_schema)
SELECT t.TABLE_SCHEMA,t.TABLE_NAME,t.TABLE_ROWS,t.CREATE_TIME,t.UPDATE_TIME FROM information_schema.TABLES t WHERE t.TABLE_SCHEMA='zabbix' ORDER BY t.TABLE_ROWS DESC;
mysql用户授权:
grant all on *.* to testTable@'%' identified by "123456";
初始化mysql实例
mysqld --defaults-file=/data0/mysql/3306/my.cnf --initialize-insecure --user=mysql
mysql导出表结构:
mysqldump -S mysql.sock -d app > app_0330.sql
dump避免gtid导出
mysqldump -S mysql.sock --set-gtid-purged=off -B app > app.sql
innobackupex恢复:
innobackupex --defaults-file=/data0/mysql/3307/my.cnf --apply-log /home/my3307back/2018-03-20_03-00-01/ innobackupex --defaults-file=/data0/mysql/3307/my.cnf --copy-back /home/my3307back/2018-03-20_03-00-01/ chown mysql.mysql -R /data0/mysql/3306/data
基于时间pos点的恢复:
mysqlbinlog --start-position=113927317 --stop-position=220222447 mysql-bin.000016 |mysql -S mysql.sock