3

I created a new user with a password in MySQL.

mysql> GRANT ALL PRIVILEGES ON simple_cms_development.*
    -> TO 'simple_cms'@'localhost'
    -> IDENTIFIED BY 'xxxxxxx';
Query OK, 0 rows affected (0.04 sec)

I checked that it was created:

mysql> SHOW GRANTS FOR 'simple_cms'@'localhost';
+-------------------------------------------------------------------------------------------------------------------+
| Grants for simple_cms@localhost                                                                                   |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'simple_cms'@'localhost' IDENTIFIED BY PASSWORD '*CA931C969BFB20B345B153F9AE0B3EBC543B48EF' |
| GRANT ALL PRIVILEGES ON `simple_cms_development`.* TO 'simple_cms'@'localhost'                                    |
+-------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

I attempted to sign in as that user and received a 1044 error:

 Macintosh-2:simple_cms kmcrayton7$ mysql -u simple_cms -p simple_csm_development;
    Enter password: 
    ERROR 1044 (42000): Access denied for user 'simple_cms'@'localhost' to database 'simple_csm_development'

Followed the steps in answer #1 and #6 and here is the result:

mysql> select user,host,password from mysql.user;
+------------+-----------+-------------------------------------------+
| user       | host      | password                                  |
+------------+-----------+-------------------------------------------+
| root       | localhost | *986BD1453A6B2F3CCF85DC695B981EE516B7613D |
| root       | macintosh | *986BD1453A6B2F3CCF85DC695B981EE516B7613D |
| root       | 127.0.0.1 | *986BD1453A6B2F3CCF85DC695B981EE516B7613D |
| root       | ::1       | *986BD1453A6B2F3CCF85DC695B981EE516B7613D |
|            | localhost |                                           |
|            | macintosh |                                           |
| simple_csm | localhost | *CA931C969BFB20B345B153F9AE0B3EBC543B48EF |
| simple_cms | localhost | *CA931C969BFB20B345B153F9AE0B3EBC543B48EF |
+------------+-----------+-------------------------------------------+
8 rows in set (0.04 sec)

mysql> exit
Bye
Macintosh-2:simple_cms kmcrayton7$ mysql -u simple_cms -p simple_csm_development;
Enter password: 
ERROR 1044 (42000): Access denied for user 'simple_cms'@'localhost' to database 'simple_csm_development'


  [1]: https://stackoverflow.com/questions/489119/mysql-error-1045-access-denied

I don't know where I'm making my mistake

I was attempting to following the suggestion below but now I can't seem to gain access at all:

Macintosh-2:simple_cms kmcrayton7$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Macintosh-2:simple_cms kmcrayton7$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Macintosh-2:simple_cms kmcrayton7$ mysql -u root 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Macintosh-2:simple_cms kmcrayton7$ mysql -u root 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Macintosh-2:simple_cms kmcrayton7$ mysql -u root 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Macintosh-2:simple_cms kmcrayton7$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Macintosh-2:simple_cms kmcrayton7$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Macintosh-2:simple_cms kmcrayton7$ 
2
  • Are you on localhost?
    – Mihai
    Commented Jan 2, 2016 at 17:01
  • I don't understand your question. I have been using the localhost:3000 in the browser while following this Rails tutorial.
    – Kim
    Commented Jan 2, 2016 at 17:04

3 Answers 3

7

I had the same issue and it solved with:

GRANT ALL PRIVILEGES ON DBName.* TO 'UserName'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
0

Your user does not have the privilege to access the database of simple_csm_development. You need to grant privileges using the grant syntax:

GRANT priv_type [(column_list)] [, priv_type [(column_list)]] ... ON [object_type] priv_level TO user_specification [, user_specification] ... [REQUIRE {NONE | ssl_option [[AND] ssl_option] ...}] [WITH {GRANT OPTION | resource_option} ...]

GRANT PROXY ON user_specification TO user_specification [, user_specification] ... [WITH GRANT OPTION]

object_type: { TABLE | FUNCTION | PROCEDURE }

priv_level: { * | . | db_name.* | db_name.tbl_name | tbl_name | db_name.routine_name }

user_specification: user [ auth_option ]

auth_option: { # Before MySQL 5.7.6 IDENTIFIED BY 'auth_string' | IDENTIFIED BY PASSWORD 'hash_string' | IDENTIFIED WITH auth_plugin | IDENTIFIED WITH auth_plugin AS 'hash_string' }

auth_option: { # As of MySQL 5.7.6 IDENTIFIED BY 'auth_string' | IDENTIFIED BY PASSWORD 'hash_string' | IDENTIFIED WITH auth_plugin | IDENTIFIED WITH auth_plugin BY 'auth_string' | IDENTIFIED WITH auth_plugin AS 'hash_string' }

ssl_option: { SSL | X509 | CIPHER 'cipher' | ISSUER 'issuer' | SUBJECT 'subject' }

resource_option: { | MAX_QUERIES_PER_HOUR count | MAX_UPDATES_PER_HOUR count | MAX_CONNECTIONS_PER_HOUR count | MAX_USER_CONNECTIONS count }

Source.

2
  • I'd like to but now I am able to gain access at all
    – Kim
    Commented Jan 2, 2016 at 16:56
  • @Kim, do you have a backup of the database? Is there another user, who has access to the database? Commented Jan 2, 2016 at 20:54
0

In all honesty, I don't know what changed but when I went through all the steps again, it worked. I'm sure there's an error on my end but I can't find it now. Thanks!

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