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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 榆社县| 盐亭县| 雷山县| 应用必备| 博客| 庆元县| 营山县| 九龙县| 青铜峡市| 阜阳市| 绥棱县| 临颍县| 石首市| 长岛县| 泰安市| 潜山县| 广灵县| 沁源县| 洛川县| 驻马店市| 抚宁县| 天峨县| 莱州市| 涞源县| 屏东市| 陆川县| 宁津县| 新昌县| 且末县| 靖边县| 明光市| 高州市| 安图县| 湘乡市| 通江县| 云南省| 陆良县| 玉门市| 黎川县| 江都市| 三明市|