I am running into a permission error when trying to load data from a flat file database dump into a new table. I know that the schema of the file and my table is the same and I tried tweaking the permissions. What else should I try?
mysql> load data infile 'myfile.txt' into table mytable fields terminated by ',' enclosed by '"';
ERROR 1045 (28000): Access denied for user 'user'#'%'
grant all on mytable.* to 'user'#'%
Here's a thread on the MySQL forums that discusses exactly this.
Here's the answer, posted by Ken Tassell
Problem resolved using the command below:
grant file on *.* to kentest#localhost identified by 'kentest1';
You might have MySQL privileges on the destination table, but you also need the FILE privilege to execute LOAD DATA, and of course the MySQL Server process needs operating-system privileges to the data file too.
Related
I try to insert some lines from csv file to MySQL database "elevage" by command line. The file is names "animal.csv". Below is my request:
`mysql> LOAD DATA LOCAL INFILE 'F:/MYSQL/animal.csv'
-> INTO TABLE Animal
-> FIELDS TERMINATED BY ';' ENCLOSED BY '"'
-> LINES TERMINATED BY '\r\n'
-> (espece, sexe, date_naissance, nom, commentaires);
and I run into this error message
`ERROR 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides`.
Then have used the following code:
`SHOW GLOBAL VARIABLES LIKE 'local_infile'`;
and I found: local_file was "OFF". Then I tried to set it to "ON" using the following code :
`SET GLOBAL local_infile=1;`
Unfortunately, I run into another error message:
`ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation`
Although, when I check the grants for the user "student" in which I'm working:
mysql> SHOW GRANTS FOR CURRENT_USER();
I get:
+--------------------------------------------------------------+
| Grants for student#localhost |
+--------------------------------------------------------------+
| GRANT USAGE ON *.* TO `student`#`localhost` |
| GRANT ALL PRIVILEGES ON `elevage`.* TO `student`#`localhost` |
+--------------------------------------------------------------+
2 rows in set (0.00 sec)
which means that "student" has all the privileges on the database "elevage".
Please advice.
The SYSTEM_VARIABLES_ADMIN privilege (as well as the deprecated SUPER privilege) is not a per-database privilege, but rather a per-server privilege. And, it's an administrators' privilege, not a users' privilege.
Why do you need such privileges to use LOAD DATA? Because that command requires its user to write files directly into the database server machine's file space. So users of that command must be completely trusted by the database server.
To use LOAD DATA LOCAL you'll need to get a server administrator to grant those privileges to you, with something like this:
GRANT SUPER, SYSTEM_VARIABLES_ADMIN ON *.* TO 'student'#'localhost';
If this is a shared server, it seems unlikely that your administrator will grant you this privilege. If it's your own server, you are the administrator, and you can use your root account either to grant your student account the privilege, or use the root account directly to run your LOAD DATA command.
I have a MySQL database in the server. I'd like to insert some data that I have in .csv format. After connecting to remote database, I try to execute below SQL statement.
LOAD DATA LOCAL INFILE '~/Downloads/words.csv'
INTO TABLE word
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Result is the error:
The used command is not allowed with this MySQL version
After doing some research, I understood that I have to enable local-infile to be able import csv to table. In order to set local-infile to 1 I execute this statement:
SET GLOBAL local_infile = 1;
Result is the error:
ERROR 1227 (42000): Access denied; you need (at least one of) the
SUPER privilege(s) for this operation
And when I try to grant all permissions to remote user with below statement
GRANT ALL PRIVILEGES ON *.* TO username#host;
I get,
You are not allowed to create a user with GRANT
even to I'm logged in as root. What do I need to do?
Create the user before giving it a grant;
CREATE USER username#host IDENTIFIED BY 'some password'
GRANT ALL PRIVILEGES ON *.* TO username#host;
I have a table in a database myDatabase in Amazon RDS. Let it be myTable.
use myDatabase;
SELECT * from myTable INTO OUTFILE 'myFile.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"'LINES
TERMINATED BY '\n';
I get this error
Error Code: 1045. Access denied for user '<<UserName>>'#'%' (using password: YES)
I tried running this command
GRANT USAGE ON *.* TO '<<UserName>>'#'%' IDENTIFIED BY '<<password>>';
flush privileges;
0 row(s) affected, 1 warning(s): 1287 Using GRANT statement to modify existing user's
properties other than privileges is deprecated and will be removed in future release. Use
ALTER USER statement for this operation.
I get this warning.
And
I am not able to export the table into a .CSV file at all.
Any idea on how to solve it ? Any thoughts on the steps which might have gone wrong ?
Make sure your user has the FILE privilege.
FILE
Affects the following operations and server behaviors:
Enables reading and writing files on the server host using the LOAD DATA and SELECT ... INTO OUTFILE statements and the LOAD_FILE()
function. A user who has the FILE privilege can read any file on the
server host that is either world-readable or readable by the MySQL
server. (This implies the user can read any file in any database
directory, because the server can access any of those files.)
Enables creating new files in any directory where the MySQL server has write access. This includes the server's data directory containing
the files that implement the privilege tables.
manual entry
I'm trying to use PHPmyadmin to import a CSV file to a mysql database, however I get a 1045 error. I get the following error:
#1045 - Access denied for user 'tipsandb_saadat'#'localhost' (using password: YES)
I know that this is a rather old question but I had the same issue with mySql 5.1.61.
What I tried to do was, from a MySql client, to run the following command:
LOAD DATA INFILE '/myProjectDir/theFile.csv'
INTO TABLE someTable
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
I gathered information from various places, tried several options and figured out that all these points must be checked:
the user must have FILE privilege:
GRANT FILE ON *.* TO 'theUser'#'%' IDENTIFIED BY 'thePassword';
the file permissions must be set so that the world can read it (actually it shall be OK if the mysqld process is able to read it):
chmod o+r theFile.csv
the file must be located in the dedicated temporary directory that is defined in the my.cnf config file:
[mysqld]
tmpdir=/tmp/mysql
every item in the file path must have its permissions set in the same fashion as the file itself
You need the FILE privilege to use this command.
I'm trying to use SQL to upload a csv file from my laptop to a database, however I get a strange error. The code I am typing into the SQL window in phpMyAdmin is as follows:
LOAD DATA INFILE '/Users/myMac/testServerUpload.csv'
INTO TABLE `testDatabase`
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
But I get the following error:
Error
SQL query:
LOAD DATA INFILE '/Users/myMac/testServerUpload.csv' INTO TABLE `testDatabase` FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
MySQL said: Documentation
#1045 - Access denied for user 'ukld'#'%' (using password: YES)
Should I be using LOAD DATA LOCAL INFILE instead of my current command as the file is on my computer? Both give me an error, and I thought LOCAL might mean that it is on the server. I could not find relevant advice searching for this error.
I had this same issue and fixed it by using LOCAL and giving the full file path:
'C:/directory/file.csv'
It seems the 1045 error comes from not having access to files on the server, which is where mySQL looks for the file if LOCAL is not specified.
See also:
http://dev.mysql.com/doc/refman/5.1/en/mysqlimport.html
You need to login as root and run:
SHOW GRANTS FOR 'ukld'#'%';
Chances are you don't have the permissions that you think you do...you need INSERT privileges on the db and table(s) into which you are trying to LOAD DATA.
UPDATE:
To correct the GRANT issue, run these statements as root in your MySQL install:
REVOKE SELECT, INSERT, UPDATE, DELETE, CREATE,
DROP, INDEX, ALTER, CREATE TEMPORARY TABLES,
LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW,
CREATE ROUTINE, ALTER ROUTINE
ON ukld.* FROM 'ukld'#'%';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE,
DROP, INDEX, ALTER, CREATE TEMPORARY TABLES,
LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW,
CREATE ROUTINE, ALTER ROUTINE
ON ukld.* TO 'ukld'#'%' IDENTIFIED BY PASSWORD 'xxx';
FLUSH PRIVILEGES;
Make sure you set the correct password in the second statement.