如果是本地可以这样,新版本的会提示有安全问题,不让into outfile:
mysql -e "select linkurl from jackxiang_mysql.boblog_links" > /tmp/linkurl.txt
mysql> select linkid,linkurl from boblog_links limit 12 into outfile "/tmp/bo-blog-url.txt";
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
show variables like '%secure%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | NULL |
+--------------------------+-------+
mysql> set global secure_file_priv="/tmp";
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable
修改/etc/my.cnf里的变量:
[mysqld]
secure_file_priv = /data/backup/mysql
注意权限:
mkdir -p /data/backup/mysql
mysql> select linkid,linkurl from boblog_links limit 12 into outfile "/data/backup/mysql/bo-blog-url.txt";
ERROR 1 (HY000): Can't create/write to file '/data/backup/mysql/bo-blog-url.txt' (Errcode: 13 - Permission denied)
chown -R mysql:mysql /data/backup/mysql
重启Mysql:service mysqld restart
mysql> show variables like '%secure%';
+--------------------------+---------------------+
| Variable_name | Value |
+--------------------------+---------------------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | /data/backup/mysql/ |
+--------------------------+---------------------+
3 rows in set (0.00 sec)
#到对应的数据库里面执行导出命令:
mysql> select linkid,linkurl from boblog_links limit 12 into outfile "/data/backup/mysql/bo-blog-url.txt";
Query OK, 12 rows affected (0.00 sec)
今天有个网友问,在用mysqldump备份时候遇到1290的错误
下面是是我模拟他的报错信息
[root@potato Desktop]# mysqldump -uroot -proot -S /tmp/mysql.sock --tab=/data/mysql/mytest_3306/data/backup lala
Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 1290: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when executing 'SELECT INTO OUTFILE'
可以很清楚地从提示看到是因为mysql服务启用了–secure-file-priv,所以才无法执行。
那么–secure-file-priv又是什么东东,应该如何解决才能是它可以备份呢?
--secure-file-priv=name :
Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files within specified directory
可以看到secure-file-priv参数是用来限制LOAD DATA, SELECT … OUTFILE, and LOAD_FILE()传到哪个指定目录的。
当secure_file_priv的值为null ,表示限制mysqld 不允许导入|导出
当secure_file_priv的值为/tmp/ ,表示限制mysqld 的导入|导出只能发生在/tmp/目录下
当secure_file_priv的值没有具体值时,表示不对mysqld 的导入|导出做限制
查看数据库当前该参数的值
root@localhost:mysql.sock 00:14:52 [(none)]>show global variables like '%secure%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_auth | ON |
| secure_file_priv | NULL |
+------------------+-------+
2 rows in set (0.00 sec)
清楚地看到secure_file_priv 的值是NULL,说明此时限制导入导出的
所以应该改变该参数
可是查看了mysql.cnf中居然没有对这个参数进行设定,就说明这个参数默认便是null
所以再mysql.cnf中的[mysqld]加入secure_file_priv =
再重启mysql服务
然后再查一下此时参数的值
root@localhost:mysql.sock 00:28:30 [(none)]>show global variables like '%secure%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_auth | ON |
| secure_file_priv | |
+------------------+-------+
2 rows in set (0.00 sec)
已经是我们要的结果
开始进行导出
[root@potato Desktop]# mysqldump -uroot -proot -S /tmp/mysql.sock --tab=/data/mysql/mytest_3306/data/backup lala
Warning: Using a password on the command line interface can be insecure.
可以看到成功了
From:https://blog.csdn.net/qq_28921653/article/details/54174341
保存到本地,你可以这样干:
mysql -e -h remote host.
=====================
show processlist 如何过滤的问题我终于知道如何解决了,From:https://mengkang.net/414.html
想show processlist里面有没有过滤的功能,但是找了好久没找到.
之后又想到导出到文件
show processlist into outfile '/tmp/sql.txt';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'into outfile '/tmp/sql.txt'' at line 1
发现show processlist并不能支持into outfile.
今天看书看到了,原来是这样用的,使用 mysql 的-e参数.
执行一段MYSQL的命令然后退出。(就是不用进客户端 在shell命令行内直接执行sql)
--execute=statement, -e statement
Execute the statement and quit.
(我设置了本地登录免密码了)
mysql -uroot -e 'show processlist\G';
不是在 mysql 里面操作,而是在 shell 命令里面直接操作.比如查看正在执行的语句有哪些(不过有的语句显示的不完整),并做好归并排序:
mysql -uroot -e 'show processlist\G'|grep 'Info'|grep -v "NULL"|awk -F ":" '{print $2}'|sort|uniq -c|sort -rn;
mysql -e "select linkurl from jackxiang_mysql.boblog_links" > /tmp/linkurl.txt
mysql> select linkid,linkurl from boblog_links limit 12 into outfile "/tmp/bo-blog-url.txt";
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
show variables like '%secure%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | NULL |
+--------------------------+-------+
mysql> set global secure_file_priv="/tmp";
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable
修改/etc/my.cnf里的变量:
[mysqld]
secure_file_priv = /data/backup/mysql
注意权限:
mkdir -p /data/backup/mysql
mysql> select linkid,linkurl from boblog_links limit 12 into outfile "/data/backup/mysql/bo-blog-url.txt";
ERROR 1 (HY000): Can't create/write to file '/data/backup/mysql/bo-blog-url.txt' (Errcode: 13 - Permission denied)
chown -R mysql:mysql /data/backup/mysql
重启Mysql:service mysqld restart
mysql> show variables like '%secure%';
+--------------------------+---------------------+
| Variable_name | Value |
+--------------------------+---------------------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | /data/backup/mysql/ |
+--------------------------+---------------------+
3 rows in set (0.00 sec)
#到对应的数据库里面执行导出命令:
mysql> select linkid,linkurl from boblog_links limit 12 into outfile "/data/backup/mysql/bo-blog-url.txt";
Query OK, 12 rows affected (0.00 sec)
今天有个网友问,在用mysqldump备份时候遇到1290的错误
下面是是我模拟他的报错信息
[root@potato Desktop]# mysqldump -uroot -proot -S /tmp/mysql.sock --tab=/data/mysql/mytest_3306/data/backup lala
Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 1290: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when executing 'SELECT INTO OUTFILE'
可以很清楚地从提示看到是因为mysql服务启用了–secure-file-priv,所以才无法执行。
那么–secure-file-priv又是什么东东,应该如何解决才能是它可以备份呢?
--secure-file-priv=name :
Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files within specified directory
可以看到secure-file-priv参数是用来限制LOAD DATA, SELECT … OUTFILE, and LOAD_FILE()传到哪个指定目录的。
当secure_file_priv的值为null ,表示限制mysqld 不允许导入|导出
当secure_file_priv的值为/tmp/ ,表示限制mysqld 的导入|导出只能发生在/tmp/目录下
当secure_file_priv的值没有具体值时,表示不对mysqld 的导入|导出做限制
查看数据库当前该参数的值
root@localhost:mysql.sock 00:14:52 [(none)]>show global variables like '%secure%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_auth | ON |
| secure_file_priv | NULL |
+------------------+-------+
2 rows in set (0.00 sec)
清楚地看到secure_file_priv 的值是NULL,说明此时限制导入导出的
所以应该改变该参数
可是查看了mysql.cnf中居然没有对这个参数进行设定,就说明这个参数默认便是null
所以再mysql.cnf中的[mysqld]加入secure_file_priv =
再重启mysql服务
然后再查一下此时参数的值
root@localhost:mysql.sock 00:28:30 [(none)]>show global variables like '%secure%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_auth | ON |
| secure_file_priv | |
+------------------+-------+
2 rows in set (0.00 sec)
已经是我们要的结果
开始进行导出
[root@potato Desktop]# mysqldump -uroot -proot -S /tmp/mysql.sock --tab=/data/mysql/mytest_3306/data/backup lala
Warning: Using a password on the command line interface can be insecure.
可以看到成功了
From:https://blog.csdn.net/qq_28921653/article/details/54174341
保存到本地,你可以这样干:
mysql -e -h remote host.
=====================
show processlist 如何过滤的问题我终于知道如何解决了,From:https://mengkang.net/414.html
想show processlist里面有没有过滤的功能,但是找了好久没找到.
之后又想到导出到文件
show processlist into outfile '/tmp/sql.txt';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'into outfile '/tmp/sql.txt'' at line 1
发现show processlist并不能支持into outfile.
今天看书看到了,原来是这样用的,使用 mysql 的-e参数.
执行一段MYSQL的命令然后退出。(就是不用进客户端 在shell命令行内直接执行sql)
--execute=statement, -e statement
Execute the statement and quit.
(我设置了本地登录免密码了)
mysql -uroot -e 'show processlist\G';
不是在 mysql 里面操作,而是在 shell 命令里面直接操作.比如查看正在执行的语句有哪些(不过有的语句显示的不完整),并做好归并排序:
mysql -uroot -e 'show processlist\G'|grep 'Info'|grep -v "NULL"|awk -F ":" '{print $2}'|sort|uniq -c|sort -rn;
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/3423/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2019-7-22 21:47
评论列表
2010-8-23 23:09 | gaston
赞
分页: 1/1 1