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.

  • 1
    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 '...';)

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



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:




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;"

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.