show processlist; # 查询当前100条;等同于select * from information_schema.processlist; show full processlist; # 查询全部; # 查询非睡眠状态的连接 select p.* from information_schema.processlist p where p.COMMAND != 'Sleep'; # 查询并发最大连接数 show variables like '%max_connections%'; # 查看当前线程连接数量信息 show status like 'Threads%';
慢查询
1 2 3 4 5 6
# 查找当前正在执行超过1分钟的线程信息 select * from information_schema.processlist where command != 'Sleep' and time > 60 order by time desc; # 不要轻易kill,注意看是否是system user或者是maxscale等代理监控的用户 # 确定是慢查询的时候,可以执行kill id的操作 # 命令行查看慢查询 mysql -ureader -pread -e 'show full processlist' | grep "select "
Access denied for user ‘root‘@’localhost’ (using password: YES)
Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
Add skip-grant-tables under [mysqld]
Restart Mysql
You should be able to login to mysql now using the below command mysql -u root -p
Run mysql> flush privileges;
Set new password by ALTER USER ‘root‘@’localhost’ IDENTIFIED BY ‘NewPassword’;
Go back to /etc/my.cnf and remove/comment skip-grant-tables
Restart Mysql
Now you will be able to login with the new password mysql -u root -p
You can’t specify target table ‘label’ for update in FROM clause
在MySQL中,写SQL语句的时候 ,可能会遇到You can’t specify target table ‘表名’ for update in FROM clause这样的错误,它的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值。 ———————————————— 版权声明:本文为CSDN博主「静远小和尚」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_29672495/article/details/72668008
比如:
1 2 3 4 5 6
update label set count=(select sum(count) from label l where (l.label_code = 'Z3' and l.name = '科普与知识') or (l.label_code = 'Z5' and l.name = '科技')) where id = '4028e5f47695023c0176950e54561000';
可以改成:
1 2 3 4 5 6 7
update label set count=(select sum(count) from (select count from label l where (l.label_code = 'Z3' and l.name = '科普与知识') or (l.label_code = 'Z5' and l.name = '科技')) tmp) where id = '4028e5f47695023c0176950e54561000';