當使用MySQL的時候,發現使用這樣的命令mysql -h 127.0.0.1 -u MySQL -p 不能訪問數據庫 root#mysql -h 127.0.0.1 -u mysql -p Enter passWord:****** ERROR 1045: Access denIEd for user: '
[email protected]' (Using passWord: YES)
原因:在127.0.0.1上的用戶mysql沒有連接localhost上MySQL的權限,可以通過如下的方式確認:
root#mysql -h localhost-u MySQL -p Enter passWord: ******
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 to server version: 4.0.20a-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql; (此DB存放MySQL的各種配置信息) Database changed mysql> select host,user from user; (查看用戶的權限情況) +-------------+-------+ | host | user | +-------------+-------+ | localhost | | | localhost | root | | localhost | | | localhost | MySQL | +-------------+-------+ 6 rows in set (0.02 sec)
由此可以看出,只能以localhost的主機方式訪問。 mysql> Grant all privileges on *.* to 'root'@'%' identifIEd by ******* with grant option; Query OK, 0 rows affected (0.02 sec) (%表示是所有的外部機器,如果指定某一台機,就將%改為相應的機器名) mysql> Grant all privileges on *.* to 'MySQL'@'%' identifIEd by ******* with grant option; Query OK, 0 rows affected (0.02 sec) (%表示是所有的外部機器,如果指定某一台機,就將%改為相應的機器名)
mysql> flush privileges; (運行為句才生效,或者重啟MySQL) Query OK, 0 rows affected (0.03 sec)
MySQL> select host,user from user; (再次查看用戶的權限情況) +-------------+-------+ | host | user | +-------------+-------+
| % | MySQL |
| % | root | | localhost | | | localhost | root | | localhost | | | localhost | MySQL | +-------------+-------+
MySQL>exit
現在再試試: root#mysql -h mysql -u root -p Enter passWord:****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 to server version: 4.0.20a-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
MySQL> 注意:
以上的設置不緊是對本機的用戶使用權限的更改,在所有外部的機器上都可以使用指定的用戶登陸連接。當使用MySQL-front在Windows下管理數據庫時,可能由於版本的問題有些程序不支持使用密碼,出現以下提示:
1251 - ClIEnt does not support authentication protocol requested by server; consider upgrading MySQL clIEnt
可以使用mymanager來管理MySQL。