I am learning MySQL and tried using a LOAD DATA
clause. When I used it as below:
LOAD DATA INFILE \"text.txt\" INTO table mytable;
MySQL use this system variable to control where you can import you files
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
So problem is how to change system variables such as secure_file_priv
.
mysqld
sudo mysqld_safe --secure_file_priv=""
now you may see like this:
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | |
+------------------+-------+
This worked for me (had the additional problem of not being able to use LOCAL with my current MySQL version in the statement LOAD DATE INFILE ... )
sudo /usr/local/mysql/support-files/mysql.server start --secure-file-priv='' --local-infile
The above works for that given path on my machine; you may have to adjust your path.
Then use:
mysql -u root -p
One important point is that you should have the CSV in the MySQL data folder. In my machine it is located at: /usr/local/mysql-8.0.18-macos10.14-x86_64/data
You can change the folder permission if needed to drop a CSV in the data folder.
Setup:
macOS Catalina version 10.15.5
MySQL version 8.0.18
If the file is local to your machine use the LOCAL in your command
LOAD DATA LOCAL INFILE "text.txt" INTO table mytable;
@vhu I did the SHOW VARIABLES LIKE "secure_file_priv";
and it returned C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\
so when I plugged that in, it still didn't work.
When I went to the my.ini
file directly I discovered that the path is formatted a bit differently:
C:/ProgramData/MySQL/MySQL Server 8.0/Uploads
Then when I ran it with that, it worked. The only difference was the direction of the slashes.
in Linux you have to edit my.cnf file in
/etc/mysql/my.cnf
and change 26 line number
param like this :
secure-file-priv= <your data path directory like /home/user/data>
then restart your MySQL and try again.
in docker you have to mount your my.cnf file with my.cnf file in your container with this command in docker-compose or add manually :
volumes:
- ./persistent:/var/lib/mysql
- ./conf/my.cnf:/etc/mysql/my.cnf
next change /conf/my.cnf in your host and config secure-file-priv param like the upper approach, in addition, you have to mount your data in mysql container and set that path for secure-file-priv param and restart your services and finally, you can load your data.
you can check your config with this command :
SHOW VARIABLES LIKE "secure_file_priv";
I had this problem on windows 10. "--secure-file-priv in MySQL" To solve this I did the following.
The server started up as expected.