1

I am trying to copy data from CSV to mysql using shell script where I am all new. And I am working with my test server.

mysql -u root -proot csv_imports -e "LOAD DATA INFILE '/var/www/html/$_csv_directory/$_csv_files' REPLACE INTO TABLE temp_test_data FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'"

I am getting error

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

If I am not working on localhost, why its giving me error of 'root'@'localhost'?

then I tried

mysql -h name-database-db-instance.something.some-server.com -P 3306 -u root -proot -e "LOAD DATA INFILE '/var/www/test.server.re/public_html/csv_files/$_csv_files' REPLACE INTO TABLE table_data FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'"

now its giving me error:

Access denied for user 'codered_db_user'@'%' (using password: YES)

  • on which server is the database ? – Archemar Dec 3 '15 at 13:47
  • 3
    I don't see your mysql command mentioning a server name: if not, then that would explain that it tries to connect to a server on localhost. – dhag Dec 3 '15 at 13:47
  • 1
    the password you give -proot must be set on database, and user root must be allowed in mysql. (grant connect to root) – Archemar Dec 3 '15 at 13:48
  • @dhag now I have set server name. but still issue is there. Please check I have edited question! – Asmita Dec 3 '15 at 13:51
  • To start with get rid of all the CSV stuff and just try to connect. Does it work if you do mysql -h servername -u root -proot? – David King Dec 3 '15 at 14:44
0

To answer your question about "localhost" you need to understand a little bit about MySQL users.

A user in MySQL is actually made up of two things:

  • the username
  • a network location

So the user 'root'@'localhost' makes up a user login for root to login from localhost. With me so far?

You are actually seeing it come up because if you do not specify a host your MySQL client will default to connect to a MySQL instance running on localhost.

So from MySQL servers point of view the login attempt is initiated by root coming from the localhost hence 'root'@'localhost'.

Regarding your password I seem to recall that some versions of the client need you to use --password not -p if you are specifying the password on the command line.

  • yes I got you. I updated my question. Next I have specified server still there is error!! Please check updation! Thanks for efforts, its helping me! – Asmita Dec 4 '15 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.