Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I ran this command-

[root@dev-img mysql]# mysql -u root -h -e "use mysql;"

and this is the output I got-

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

Is there anything wrong with my command? I've searched everywhere and the syntax seems to be as above.

share|improve this question

migrated from Dec 12 '12 at 16:28

This question came from our site for professional and enthusiast programmers.

Off-topic; belongs on Database Administrators – Jim Garrison Dec 12 '12 at 5:08
I normally use ssh tunnels to access remote mysql databases. My platform is MacOSX. I use Sequel Pro to access mysql remote sites using a ssh connection. Restated ... I use public/private keys for ssh access to the machine and then access mysql databases 'locally'. – kjtl Dec 12 '12 at 5:27

Two possible problems

  1. You didn't specify the -p option. Without -p the client will not prompt for a password and will attempt to connect without one
  2. The database may not be configured to allow remote login for root. You may have to login on the server and enable remote access (i.e. GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '...';)
share|improve this answer

I will add though that allowing root from remote clients (especially allowing root from '%' ) is VERY BAD security wise

share|improve this answer


How Do I Grant Access To An Existing Database?

Let us assume that you are always making connection from remote IP called for database called webdb for user webadmin, To grant access to this IP address type the following command At mysql> prompt for existing database, enter:

mysql> update db set Host='' where Db='webdb';
mysql> update user set Host='' where user='webadmin';

Review complete info:

Aditional Info:


share|improve this answer

You need to make sure there exists a user root@ with privileges to the database mysql.

If you have access to the mysql instance another way, do the following to see what privileges this user has:

show grants for root@'';

The results should look something like the following:

grant all privileges on mysql.* to 'root'@'' identified by password 'XXXX';

If you don't see results for that "show" statement above, then use the "grant" statement above to give the privileges.

If the IP address you are connecting from changes often, you can open it up to the wildcard host %, like:

grant all privileges on mysql.* to 'root'@'%' identified by password 'XXXX';

but that's not terribly secure.

(If you don't have access, ask your DBA/webhost to do that.)

Then you can connect using that statement, but add the -p flag so you can enter your password:

mysql -u root -p -h -e "use mysql;"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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