简体   繁体   中英

#1045 - Access denied for user 'root'@'localhost' (using password: YES) while exporting data using mysql select query

This is the query I'm running in PhpMyAdmin .

SELECT 
    name,mobile,email,address
FROM
    customer
WHERE
  status = 'Active' 
INTO OUTFILE 'C:/tmp/active_customers.csv' 
FIELDS ENCLOSED BY '"' 
TERMINATED BY ';' 
ESCAPED BY '"' 
LINES TERMINATED BY '\r\n';

And getting this error:

#1045 - Access denied for user 'root'@'localhost' (using password: YES)

Your user does not have permission to query SELECT FROM CUSTOMER . In order to fix this (assuming you have SSH access) :

  1. Connect to MySQL server using SSH using a user which has access (or owns) MySQL : ssh mysql@your_mysql_server.com

  2. Login to MySQL server as root with password:

    mysql -u root -p

  3. Grant required permissions to the user you want (check the available permissions here ):

    GRANT [ALL/SELECT/etc..] ON database.table TO 'lptool_app'@'localhost';

  4. After finishing granting the privileges you want, It's best practice to reload all of the privileges:

    FLUSH PRIVILEGES;

  5. You can check the privileges granted to any user using this command :

    SHOW GRANTS FOR 'user'@'server';

  6. Using a privileged user (like root ), you can run the same queries with PHPMyAdmin as well.

  7. NOTE: The permissions are granted to user@machine, not user only so, if you grant your permissions to a specific user@machine, your user won't have the same permissions from another machine. But if you are only working from PHPMyAdmin, as it runs on a server, your machine won't change, therefore you should not be having problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM