mysql执行sql文件的方式

sql文件内容(用于批量打印锁表进程):

1
2
3
[root@ruimysql ~]# cat /home/mysql/scripts/kill_locked.sql 
select group_concat(concat('kill ',id) separator '; ') as cmd from information_schema.processlist where user='test';
[root@ruimysql ~]#

第一种:在linux终端下执行:

1
2
3
4
5
[root@ruimysql ~]# 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; kill 160229; kill 160242; kill 160253; kill 160240; kill 160227
[root@ruimysql ~]#

第二种:在己连接mysql终端下执行:

1
2
3
4
5
6
7
8
9
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
# mysql
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×