Creo un utente MySQL come segue:
mysql> grant all privileges on *.* to mysql@"%" IDENTIFIED by "myPassword" with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql> exit;
Bye
Quindi provo ad accedere con l'utente appena creato ma non funziona.
% mysql -u mysql -pmyPassword
ERROR 1045 (28000): Access denied for user "mysql"@"localhost" (using password: YES)
%
Perché?
risposte:
7 per risposta № 1Credo che localhost sia speciale e non coperto dal "%".
Problema
mysql> grant all privileges on *.* to mysql@"localhost" IDENTIFIED by "myPassword" with grant option;
e dovrebbe funzionare
5 per risposta № 2
Sembra contro-intuitivo, ma "localhost" non è compensato da "%"
in MySQL. Il motivo è tutto "%"
corrisponde a tutte le connessioni TCP / IP, ma le connessioni da "localhost" sono mappate al socket del dominio unix.
Ci sono due soluzioni possibili:
Fai una sovvenzione extra per l'utente su "localhost":
mysql> grant all privileges on *.* to mysql@"localhost" IDENTIFIED by "myPassword" with grant option;
PS: non devi FLUSH PRIVILEGES dopo GRANT.
Forza l'accesso tramite TCP / IP:
% mysql -u mysql -pmyPassword -h 127.0.0.1