I’ve just created a new MySQL user with a password and granted them all privileges on a database. Now I’d like to connect to that database, with the password I just set, and I can’t:
mysql> create user 'reviews' identified by 'reviews';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on reviews.* to 'reviews'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
$ mysql -U reviews -u reviews -p
Enter password:
ERROR 1045 (28000): Access denied for user 'reviews'@'localhost' (using password: YES)
What am I doing wrong? I’m working on MacOS Lion in a bash shell, version 10.6 of MySQL.
The CREATE USER statement needs a host-part when you define the user. Otherwise it will use the default ‘%’ and since the GRANT statement includes @’localhost’, you end up with a user with a password, and the other without.
Results in:
Use the following to get what you want:
Note that it is best specify the database when you connect, otherwise you’ll need to change the default database after connecting: