ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)解決 朋友問我問題: m三ysql 升級了 5.0 -- 5.5導入的數據沒問題, grant all privileges on *.* to test@'12.12.12.12';報錯ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 我剛開始懷疑密碼不對,讓他換成grant all privileges on *.* to test@'12.12.12.12' identified by 'xxx'; 也不行 再換成grant all privileges on *.* to test@'12.12.12.12' identified by '';也不行
mysql> grant all privileges on *.* to test@'12.12.12.12' identified by ''; ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 但是執行如下命令成功了 mysql> grant select on *.* to test@'12.12.12.12' identified by ''; Query OK, 0 rows affected (0.01 sec)
我懷疑當前的root帳號權限問題,讓他執行show grants;
[sql] mysql> show grants; +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Grants for root@localhost | +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'root'@'localhost' WITH GRANT OPTION | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON `mysql`.* TO 'root'@'localhost' | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3 rows in set (0.00 sec) 果然問題出來了,因為正常的root帳號權限如下: [html] mysql> show grants; +---------------------------------------------------------------------+ | Grants for root@localhost | +---------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql>
他的root帳號沒有all privileges,所以分配別人all的時候就會報錯。 我讓他用mysqladmin重置root帳號試試看
/usr/local/mysql/bin/mysqladmin –u root password ‘’;