Java世界

          學習筆記

          常用鏈接

          統計

          積分與排名

          天籟村

          新華網

          雅虎

          最新評論

          mysql創建新用戶并設權限命令

          當使用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: 'mysql@127.0.01' (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。

          posted on 2008-06-17 13:32 Rabbit 閱讀(3055) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 广昌县| 岢岚县| 贺州市| 东港市| 临桂县| 德保县| 崇礼县| 广丰县| 双桥区| 无锡市| 武穴市| 师宗县| 谢通门县| 咸阳市| 镇巴县| 陆丰市| 遵义市| 苍溪县| 池州市| 库伦旗| 开远市| 惠东县| 通河县| 福海县| 婺源县| 河北省| 宁远县| 泗洪县| 泸州市| 安图县| 仁寿县| 基隆市| 嘉兴市| 象州县| 博客| 潞城市| 固阳县| 武川县| 寻乌县| 洛阳市| 安化县|