工作中常用命令參考,收集如下: 查詢表大小:select table_name, data_length from information_schema.tables where table_schema='testTable'; 查詢表行數(基於information_schema)SELECT ...
工作中常用命令參考,收集如下:
查詢表大小:
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