[关闭]
@xtccc 2018-07-02T12:01:52.000000Z 字数 1304 阅读 1866

MySQL tuning

Database



目录

操作


mysqladmin

查看状态

  1. $ mysqladmin status
  2. Uptime: 14279918 Threads: 1501 Questions: 2808466184 Slow queries: 498932 Opens: 75710 Flush tables: 1 Open tables: 2000 Queries per second avg: 196.672



slow query

  1. mysql> show variables like '%slow%';
  2. +---------------------------+-----------------------------------------+
  3. | Variable_name | Value |
  4. +---------------------------+-----------------------------------------+
  5. | log_slow_admin_statements | OFF |
  6. | log_slow_slave_statements | OFF |
  7. | slow_launch_time | 2 |
  8. | slow_query_log | OFF |
  9. | slow_query_log_file | /var/lib/mysql/devmysql-01-dev-slow.log |
  10. +---------------------------+-----------------------------------------+
  11. 5 rows in set (0.00 sec)




允许用户访问数据库

参考 How To Create a New User and Grant Permissions in MySQL

  1. GRANT ALL PRIVILEGES ON pge.* to 'demo'@'localhost' WITH GRANT OPTION;

这个方法只能适用于给定的hostname。

如果希望允许用户从任何地方访问,改成:

  1. GRANT ALL PRIVILEGES ON pge.* to 'demo'@'%' WITH GRANT OPTION;

则会报错:

Can't find any matching row in the user table



参考 这里






Slow Query


enable slow query



Find and Kill Pending Queries


显示正在运行的query

  1. show full processlist;

或者

  1. SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST ;

image_1chchla4j1nf71poa11e61nl319q49.png-280.5kB

time就是执行的时长,STATE是当前状态

如果要kill某个query,用这个命令: kill <ID> ;

如果想条件性地找到并kill一批queries,首先找到这些ID:

  1. SELECT CONCAT('KILL ',ID,';')
  2. FROM INFORMATION_SCHEMA.PROCESSLIST
  3. WHERE USER = 'akka_aurora'
  4. AND STATE = 'cleaned up';

然后执行这些结果。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注