select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/test.txt';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
查看官网:
1.如果secure_file_priv 的值为空的话,这个变量将不起作用;
2.如果secure_file_priv的值为路径的话,则mysql服务器将限制导入导出操作功能在这个设置的路径下使用。这个路径必须存在。
3.如果secure_file_priv的值设置为空的话,mysql服务器不能使用导出导入操作功能.但是,在mysql 5.7.6下是可以操作的。
所以,也就是说,要找到secure_file_priv这个变量,并且将其设置为我们想要存放数据的路径就可以了
mysql> show global variables like '%secure%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_auth | ON |
| secure_file_priv | NULL |
+------------------+-------+
2 rows in set (0.01 sec)
-- 限制mysqld 不允许导入导出
解决办法:
给这个参数指定目录,!有一点需要注意,那就是要确保你设置的路径mysql具有读写权限
[root@localhost tmp]# grep secure_file_priv /usr/local/mysql5.6/my.cnf
secure_file_priv = /tmp
-- 限制mysqld的导入导出只能发生在/tmp/目录下
secure_file_priv=' ' -- 不对mysqld 的导入 导出做限制
重启mysql
[root@localhost tmp]# ps -ef|grep mysql
root 6115 5302 0 22:55 pts/2 00:00:00 /bin/sh /usr/local/mysql5.6/bin/mysqld_safe --defaults-file=/usr/local/mysql5.6/my.cnf
mysql 6638 6115 0 22:55 pts/2 00:00:00 /usr/local/mysql5.6/bin/mysqld --defaults-file=/usr/local/mysql5.6/my.cnf --basedir=/usr/local/mysql5.6 --datadir=/data/mysql3307/data --plugin-dir=/usr/local/mysql5.6/lib/plugin --user=mysql --log-error=/data/mysql3307/log/error.log --open-files-limit=65535 --pid-file=/data/mysql3307/log/git-server.pid --socket=/tmp/mysql3307.sock --port=3307
pkill mysql
[root@localhost tmp]# /usr/local/mysql5.6/bin/mysqld_safe --defaults-file=/usr/local/mysql5.6/my.cnf &
[1] 6115
[root@localhost tmp]# 170821 22:55:15 mysqld_safe Logging to '/data/mysql3307/log/error.log'.
170821 22:55:15 mysqld_safe Starting mysqld daemon with databases from /data/mysql3307/data
mysql> show global variables like '%secure%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_auth | ON |
| secure_file_priv | /tmp/ |
+------------------+-------+
mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/test.txt';
Query OK, 1 row affected (0.00 sec)
[root@localhost tmp]# cat /tmp/test.txt
KILL 1;
通过information_schema.processlist表中的连接信息生成需要处理掉的MySQL连接的语句临时文件,然后执行临时文件中生成的指令。
复制代码 代码如下:
mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root';
+------------------------+
| concat('KILL ',id,';') |
+------------------------+
| KILL 3101; |
| KILL 2946; |
+------------------------+
2 rows in set (0.00 sec)
mysql>select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt';
Query OK, 2 rows affected (0.00 sec)
mysql>source /tmp/a.txt;
Query OK, 0 rows affected (0.00 sec)
参考链接
http://www.jb51.net/article/65718.htm