Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow user to login to MySQL?

As a root mysql user, I executed the following:

grant all on mydb.* to john identified by 'john1';

Then from shell, I tried to login via

mysql -h localhost -u john -pjohn1;

But when I do this, I get the error

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

How do I allow john to login to the mysql terminal? Do I need to use the root mysql user to change something in the mysql.user table?

Thanks

like image 438
John Avatar asked Mar 09 '10 21:03

John


People also ask

How do I grant access to a MySQL user?

To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name. * TO 'username'@'localhost';

How do I create a user and grant privilege in MySQL?

To create a user with the same privileges as the root user, use the following command, which grants global privileges to the user Janet connecting via localhost: mysql> GRANT ALL ON *. * TO 'janet'@'localhost' WITH GRANT OPTION; The WITH GRANT OPTION clause allows users to grant their privileges to other users.


1 Answers

Try

GRANT ALL PRIVILEGES on mydb.* to 'john'@'localhost' identified by 'john1';

Or maybe the problem is because you're not specifying the schema. Add "mydb" to the end of your login console command:

mysql -h localhost -u john -pjohn1 mydb

Docs: http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

like image 191
adamJLev Avatar answered Oct 08 '22 07:10

adamJLev