mysql执行sql文件的两种方式

sql文件内容: (用于批量kill锁表进程)
[root@czz ~]# cat /home/mysql/scripts/kill_locked.sql 
select group_concat(concat('kill ',id) separator '; ') as cmd from information_schema.processlist where user='test';
[root@czz ~]# 

 

第一种:在linux终端下执行:
[root@czz ~]# mysql -utest -p123456 <  /home/mysql/scripts/kill_locked.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
cmd
kill 160234; kill 160233; kill 160237; kill 160235; kill 160236; kill 160251; kill 160238; kill 160239
[root@czz ~]# 

 

第二种:在己连接mysql终端下执行:
mysql> \. /home/mysql/scripts/kill_locked.sql
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| cmd                                                                                                                                                        |
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| kill 160234; kill 160233; kill 160235; kill 160236; kill 160229; kill 160227; kill 160232; kill 160225                                                     |
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.03 sec)

mysql> quit

 

 

 

转载于:https://www.cnblogs.com/ruigu/p/10756508.html

你可能感兴趣的:(mysql执行sql文件的两种方式)