问题描述:mysqldump备份时报错mysqldump: Got error: 1290: The MySQL server is running with the --secure-file-priv option,如下所示:
数据库:mysql 5.7.21
1、问题重现
[root@leo-mysql5721 ~]# mysqldump -uroot -p --tab=/backup booksDB
Enter password: 
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'
2、解决方案
2.1、参数确认
[root@leo-mysql5721 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like '%secure%';
+--------------------------+-----------------------+
| Variable_name            | Value                 |
+--------------------------+-----------------------+
| require_secure_transport | OFF                   |
| secure_auth              | ON                    |
| secure_file_priv         | /var/lib/mysql-files/ |   --限制mysqld的导入导出只能发生在默认的/var/lib/mysql-files/目录下
+--------------------------+-----------------------+
3 rows in set (0.00 sec)

mysql> show variables like '%basedir%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| basedir       | /usr/ |
+---------------+-------+
1 row in set (0.00 sec)

mysql> select @@basedir from dual;
+-----------+
| @@basedir |
+-----------+
| /usr/     |
+-----------+
1 row in set (0.00 sec)

mysql> show global variables like '%tmpdir%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| innodb_tmpdir     |       |
| slave_load_tmpdir | /tmp  |
| tmpdir            | /tmp  |
+-------------------+-------+
3 rows in set (0.00 sec)
2.2、修改配置文件
[root@leo-mysql5721 etc]# pwd
/etc
[root@leo-mysql5721 etc]# vi my.cnf
添加如下:
secure-file-priv=""
--确认
mysql> show variables like '%secure%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| require_secure_transport | OFF   |
| secure_auth              | ON    |
| secure_file_priv         |       |
+--------------------------+-------+
3 rows in set (0.00 sec)

3、再次备份
[root@leo-mysql5721 ~]# mysqldump -uroot -p -hlocalhost --tab=/tmp booksDB
Enter password: 

[root@leo-mysql5721 tmp]# ls -ltr
total 32
-rw-------. 1 root   root      0 Jun 23 08:47 yum.log
drwxr-xr-x. 2 root   root     18 Jun 23 08:49 hsperfdata_root
-rwx------. 1 root   root    836 Jun 23 08:55 ks-script-8lHwuU
drwx------. 3 root   root     17 Jun 23 08:56 systemd-private-796ca56c188942b08f0997022d3e8f17-vmtoolsd.service-cG7DC9
drwx------. 3 root   root     17 Jun 23 08:56 systemd-private-796ca56c188942b08f0997022d3e8f17-rtkit-daemon.service-Xe3Eku
-rw-r--r--. 1 root   root      0 Jun 23 08:56 storage.log
-rw-r--r--. 1 root   root      0 Jun 23 08:56 program.log
-rw-r--r--. 1 root   root      0 Jun 23 08:56 packaging.log
-rw-r--r--. 1 root   root      0 Jun 23 08:56 sensitive-info.log
-rw-r--r--. 1 root   root      0 Jun 23 08:56 ifcfg.log
drwx------. 3 root   root     17 Jun 23 08:56 systemd-private-796ca56c188942b08f0997022d3e8f17-cups.service-Zxcwvz
-rw-r--r--. 1 root   root   1283 Jun 23 08:56 anaconda.log
drwx------. 3 root   root     17 Jun 23 08:56 systemd-private-796ca56c188942b08f0997022d3e8f17-colord.service-wZRrBT
drwx------. 2 liujun liujun   25 Jun 23 09:01 ssh-nGJMLEiC7fhz
drwx------. 2 liujun liujun    6 Jun 23 09:01 tracker-extract-files.1000
drwxr-xr-x. 2 liujun liujun    6 Jun 23 09:01 hsperfdata_liujun
-rw-r--r--. 1 root   root   1576 Jun 24 23:08 authorbook.sql
-rw-rw-rw-. 1 mysql  mysql    88 Jun 24 23:08 authorbook.txt
-rw-rw-rw-. 1 mysql  mysql   135 Jun 24 23:08 authors.txt
-rw-r--r--. 1 root   root   1408 Jun 24 23:08 authors.sql
-rw-rw-rw-. 1 mysql  mysql   218 Jun 24 23:08 books.txt
-rw-r--r--. 1 root   root   1387 Jun 24 23:08 books.sql

说明:如上所示,备份无异常发生,且authorbook.sql、authorbook.txt、authors.txt、authors.sql、books.txt、books.sql为备份文件.