I am using MySQL version 5.5 and I am trying to use load data infile and I am getting errors. I've looked at the documentation and it looks like I am doing exactly what the docs specify.
Running this command in mysql
LOAD DATA local infile '/home/pi/Downloads/load_data_infile.txt'
INTO TABLE test_tbl FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
Gives the following error.
ERROR 1148 (42000): The used command is not allowed with this MySQL version
Running the following command
LOAD DATA local-infile '/home/pi/Downloads/load_data_infile.txt'
INTO TABLE test_tbl FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
Gives the following error
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 '-infile '/home/pi/Downloads/load_data_infile.txt' INTO TABLE test_tbl FIELDS TER' at line 1
What is wrong with my syntax? The data in the file is
126,126text,moretext
127,127text,moretext
1 Answer 1
CLIENT SIDE
Before you run this
LOAD DATA local infile '/home/pi/Downloads/load_data_infile.txt'
INTO TABLE test_tbl FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
You need to start mysql client program with --local-file
mysql --local-file -uroot -p
If you wish to have this configured permanantly, add this to ~/.my.cnf
[mysql]
local-infile
This forces the mysql client program to execute.
SERVER SIDE
The mysqld (server side must be started with local_infile) in its my.cnf
or my.ini
.
Make sure to add this
[mysqld]
local_infile=1
and run
service mysql restart
If you cannot config it and restart it, login to mysql and run
mysql> SELECT @@global.local_infile;
or
mysql> SHOW GLOABL VARIABLES LIKE 'local_infile';
If you get 0
, you cannot execute LOAD DATA LOCAL INFILE
no matter what you do to the client side.
SUPPLEMENTAL INFO
Running the following command
LOAD DATA local-infile '/home/pi/Downloads/load_data_infile.txt'
INTO TABLE test_tbl FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
Gives the following error
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 '-infile '/home/pi/Downloads/load_data_infile.txt' INTO TABLE test_tbl FIELDS TER' at line 1
That's just a straight up syntax error.
Get rid of the dash between local
and infile
so that it reads
LOAD DATA local infile '/home/pi/Downloads/load_data_infile.txt'
INTO TABLE test_tbl FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
-
The ` @@global.local_infile` is
1
. TriedLOAD DATA local-infile '/home/pi/Downloads/load_data_infile.txt' INTO TABLE test_tbl FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
. I am getting the same errorERROR 1148 (42000): The used command is not allowed with this MySQL version
. If i uselocal-infile
I getERROR 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 '-infile '/home/pi/Downloads/load_data_infile.txt' INTO TABLE test_tbl FIELDS TER' at line 1
newdeveloper– newdeveloper2019年09月27日 21:53:53 +00:00Commented Sep 27, 2019 at 21:53 -
I mentioned already at the bottom of my post :
That's just a straight up syntax error.
. Please Get rid of the dash betweenlocal
andinfile
.RolandoMySQLDBA– RolandoMySQLDBA2019年09月27日 22:08:48 +00:00Commented Sep 27, 2019 at 22:08 -
In my original post I did. I just tried again and I get the same error.
ERROR 1148 (42000): The used command is not allowed with this MySQL version
newdeveloper– newdeveloper2019年09月28日 00:48:52 +00:00Commented Sep 28, 2019 at 0:48 -
Not sure but now it is working. I added
local-infile=1
to my.my.cnf
file restarted mysql but notihng. Added it back to.my.cnf
then rebooted the machine and it worked.newdeveloper– newdeveloper2019年09月28日 09:55:37 +00:00Commented Sep 28, 2019 at 9:55 -
Thank you for accepting my answer. That’s why I gave both client side and server side. Once you did both, things worked.RolandoMySQLDBA– RolandoMySQLDBA2019年09月28日 11:55:57 +00:00Commented Sep 28, 2019 at 11:55
LOCAL
? does your client works with remote MySQL, and source file is local for client and remote for server really? Check doesLOAD FILE LOCAL
allowed both on server and on cilent side either by proper settings in INI file or by proper command line options.ini
file but that could lead it issues.