mysqldump Got error 1290

eric0435發表於2020-07-27

在用mysqldump備份時候遇到1290的錯誤

[mysql@localhost ~]$ mysqldump -uroot -pxxzx7817600 --tab=/mysqldata/tmp  query_rewrite
mysqldump: [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,所以才無法執行。這個選項或系統變數用被來限制透過load data和select ... into outfile語句和load_file()函式所執行匯入和匯出操作的資料量。

secure_file_priv有以下設定:
.如果為空,變數不生效。沒有安全設定。
.如果設定為一個目錄名,伺服器對匯入和匯出操作只對這個目錄中的檔案生效,但目錄必須存在,伺服器不會建立目錄。
.如果設定NULL,伺服器禁止匯入和匯出操作。

檢視資料庫當前設定:

mysql> show global variables like '%secur%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| require_secure_transport | OFF   |
| secure_auth              | ON    |
| secure_file_priv         | NULL  |
+--------------------------+-------+
3 rows in set (0.01 sec)

看到secure_file_priv當前設定為NULL,說明限制匯入和匯出操作。

檢視配置檔案my.cnf發現沒有設定secure_file_priv引數,那麼這個引數預設應該是為NULL。

[mysql@localhost mysql]$ cat my.cnf
[mysqld]
basedir=/mysqlsoft/mysql
datadir=/mysqldata/mysql
bind-address=*
user=mysql
port=3306
log-error=/mysqldata/mysql/mysql.err
pid-file=/mysqldata/mysql/mysqld.pid
socket = /mysqlsoft/mysql/mysql.sock
character-set-server=utf8mb4
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
innodb_flush_method=O_DIRECT
binlog_format = mixed
log-bin=/mysqldata/mysql/binlog
max_binlog_size = 100m
binlog_cache_size = 4m
server-id=1

修改配置檔案my.cnf參加secure_file_priv=

[mysql@localhost mysql]$ vi my.cnf
.....
secure-file-priv=

重啟mysql資料庫

[root@localhost ~]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL.. SUCCESS!

再次檢查secure_file_priv引數設定

mysql> show global variables like '%secur%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| require_secure_transport | OFF   |
| secure_auth              | ON    |
| secure_file_priv         |       |
+--------------------------+-------+
3 rows in set (0.00 sec)

再執行匯出操作成功

[mysql@localhost ~]$ mysqldump -uroot -pxxzx7817600 --tab=/mysqldata/tmp  mysql
mysqldump: [Warning] Using a password on the command line interface can be insecure.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2707293/,如需轉載,請註明出處,否則將追究法律責任。

相關文章