I have access to my databases on phpmyadmin and mysql Workbench on my local computer but I have a problem when I try to access the server using Terminal.

Originally, I had uploaded the databases on phpmyadmin. When I utilized Workbench after running new server instance localhost, I had automatic access to my databases. However, when I run mysql command in terminal and show databases, only the default information-schema and test database show up.

Furthermore, when I try to execute the .sql files to import the database on terminal, I get the following error:

ERROR 1046 (3D000) at line 11: No database selected.

After reading through the documentation, I thought the issue was that I didn't start off the script with USE Database db_name. I then implemented that in the file and then I got this message in terminal:

ERROR 1044 (42000) at line 7: Access denied for user ''@'localhost' to database 'database'.

If I have access to my databases on phpmyadmin and on Workbench, shouldn't it be the same in terminal?

Also when I first run in terminal mysql -u admin -p < text-file, it asks me for my password. If I simply press enter, then I receive the aforementioned ERROR 1046 or ERROR 1044.

If I put in my password, I then receive the following error:

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

Can someone please help?

  • This is more of a server administration question than a programming question; probably belongs on ServerFault.
    – Justin
    Commented Sep 29, 2011 at 20:03

2 Answers 2


It could be your admin user is connecting from [email protected].

Assuming admin is the actual user you have privileges on, try connecting through:

> mysql -h -u admin -p

The way MySQL handles users, the host is very important, and in this case is different than localhost.

If your phpMyAdmin user has access to the mysql database, you can the following statement to see what user/host combinations exist on your install.

 SELECT User, Host FROM mysql.user

Have you created an admin@localhost user in MySQL via a GRANT query? e.g.

GRANT ALL PRIVILEGES ON *.* TO admin@localhost IDENTIFIED BY 'yourpassword';

Since you say phpmyadmin is working, you can check for the existence of this account via phpmyadmin by issuing a

SHOW GRANTS FOR admin@localhost

query. It'll show what (if any) rights that account has.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.