LOAD DATA INFILE + MySQL error 28000 LOAD DATA INFILE + MySQL error 28000 sql sql

LOAD DATA INFILE + MySQL error 28000


You can try LOAD DATA LOCAL INFILE and use a file stored in the client's disk. This way you don't need to have FILE permission. It will be slower since the file has to be uploaded to server.

Hope this help


To begin with, please, show us your config file (my.cnf) and verison of the database. Also, code output where connection is estableshed would be helpful. It should be something like:

/*** mysql hostname ***/$hostname = 'localhost';/*** mysql username ***/$username = 'user';/*** mysql password ***/$password = 'pass';function testdb_connect ($hostname, $username, $password){    $dbh = new PDO("mysql:host=$hostname;dbname=database", $username, $password);    return $dbh;}try {    $dbh = testdb_connect ($hostname, $username, $password);    echo 'Connected to database';} catch(PDOException $e) {    echo $e->getMessage();}

As for the errors:

ERROR 1045 (28000) at line 1: Access denied for user 'user'@'localhost'andERROR 1148 (42000) at line 1: The used command is not allowed with this MySQL version

Do you get an error if you execute:

/usr/bin/mysql --host=localhost --user=theuser --password=password --database=db_database<<EOFMYSQLshow tables;EOFMYSQL

One thing you might check is (which requires you to login to the MySQL console) - check to make sure that you have permissions to login to MySQL via localhost:

mysql -h 127.0.0.1 -u user -pmysql> select user,host from mysql.user;+------+--------------------------------+| user | host                           |+------+--------------------------------+| user | 127.0.0.1                      | | user | ::1                            || user | localhost                      | <-- Make sure you have a localhost entry for root+------+--------------------------------+3 rows in set (0.00 sec)

Also, you may check GRANTS for your user.To list the privileges granted to the account that you are using to connect to the server, you can use any of the following statements:

SHOW GRANTS;SHOW GRANTS FOR CURRENT_USER;SHOW GRANTS FOR CURRENT_USER();

Just to be sure that there is the issue with privileges, you mat try the following:

sudo service mysql stopsudo mysqld --skip-grant-tables

And execute LOAD command then.

UPDATE

As for your config file, for security reasons you have:

[mysqld]local-infile=0

If LOAD DATA LOCAL is disabled, either in the server or the client, a client that attempts to issue such a statement receives the following error message:

ERROR 1148: The used command is not allowed with this MySQL version

What you can it is set all users except 'admin' and 'root' (for instance) to not have that privilege at the mysql level, then login to MySQL and run the query:

UPDATE mysql.user SET File_priv='N' WHERE user!='da_admin' AND user!='root';FLUSH PRIVILEGES;

For the command line try to use only "--local-infile" insted of "--local-infile=1" and let us know the result.


LOAD DATA INFILE

This directive is used to load files that are located on the server.

To use LOAD DATA INFILE, make sure:

  • the connecting user has the FILE privilege. See 6.2.1 Privileges Provided by MySQL.

  • the server has sufficient (filesystem) permissions to read the file.

  • that if the secure_file_priv system variable is set, the file is located in that directory. The server will not load any files outside of that directory.

LOAD DATA LOCAL INFILE

This directive is used to load files that are located on the client.

To use LOAD DATA INFILE, make sure:

  • the MySQL client is compiled with -DENABLED_LOCAL_INFILE=1. LOAD DATA LOCAL INFILE cannot work without it.

    Most distributions are compiled with this flag, but some are not. This is mostly an issue where MySQL is compiled manually.

  • the MySQL server is started with the option --local-infile=1.

    You can also set local-infile=1 under the group [mysqld], so it is enabled automatically when the server starts.

    LOAD DATA LOCAL INFILE cannot work without it.

  • the option loose-local-infile=1 is set under the group [client]. This isn't always needed, but it's better to make sure this isn't an issue.

  • To use LOAD DATA LOCAL INFILE in PHP, you need to set the driver-option PDO::MYSQL_ATTR_LOCAL_INFILE to true when constructing a new database handle. See MySQL Functions (PDO_MYSQL)

    This must be done when constructing a new PDO instance. Setting it afterwards with PDO::setAttribute() will not work.

See 6.1.6 Security Issues with LOAD DATA LOCAL for more details.