Ubuntu18.04 ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so...

在ubuntu18.04中运行mysql导出和输入文件发现报错:ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
实际上是因为导入或输出的文件夹没有权限
在mysql中运行:

mysql> show variables like '%secure%';

结果发现我的导出路径不是secure_file_priv默认的路径

+--------------------------+-----------------------+
| Variable_name            | Value                 |
+--------------------------+-----------------------+
| require_secure_transport | OFF                   |
| secure_auth              | ON                    |
| secure_file_priv         | /var/lib/mysql-files/ |
+--------------------------+-----------------------+

接下来,更改secure_file_priv,打开

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

添加

secure_file_priv =

这样可以在任何文件位置导入和输出mysql数据
重启mysql就可以了

sudo service mysql restart

近期发现即便这样更改后仍可能报错(2020.09):

DBD::mysql::st execute failed:File “XXX”not found(Errcode:1-Permission denied)

解决的办法是:

vim /etc/apparmor.d/usr.sbin.mysqld

添加tmp文件及你需要倒入数据文件夹的权限

/tmp/** rwk,
/home/username/input_file_folder_name/ r,
/home/username/input_file_folder_name/** rwk,

完成后重启apparmor

sudo service apparmor restart

另外,进入mysql 删除之前报错的itbl:

Drop tables itbl_xxx

重启mysql即可用

sudo service mysql restart

你可能感兴趣的:(Ubuntu18.04 ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so...)