同一個目標,同一個夢想

          One Target,One Dream
          posts - 25, comments - 11, trackbacks - 0, articles - 37

          MySQL密碼丟失解決和密碼重置

          Posted on 2010-08-18 22:56 J2EE Home工作室 閱讀(4953) 評論(0)  編輯  收藏 所屬分類: MySQL
          這個MySQL有點怪啊,突然間用原賬號就登陸不上了(具體原因不詳,有知道的告訴我);所以決定修改下原密碼。
          1.停掉MySQL,然后用無權限驗證的方式重新啟動MySQL 命令:
          Linux下,運行 /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
          Windows下,在命令行下運行 X:/MySQL/bin/mysqld --skip-grant-tables
          2.在命令行下用,mysql -u -root登陸
          3.修改下密碼吧,一位博主(http://blog.chinaunix.net/u/29134/showart_373855.html)寫的方法比較全,我就不羅嗦了。三種方法任何一個都行
          新手在這個上往往容易范錯誤,導致不能進入MYSQL,整得非常郁悶。
          我來做幾個例子相信很快就明白了 。
          1、原來的密碼是123456
          C:\>type mysql5.bat
          @echo off
          mysql -uroot -p123456 -P3306
          正確的修改MYSQL用戶密碼的格式是:
          我們這里用
          用戶:root(可以換成其他的)
          密碼:woshiduide
          來演示新密碼。

          C:\>mysqladmin -uroot -p password woshiduide
          Enter password: ******
          于是修改成功。
          注意PASSWORD關鍵字后面的空格

          有好多人是這樣修改的:
          C:\>mysqladmin -uroot -p password 'woshiduide'
          Enter password: ******

          C:\>mysqladmin -uroot -p password 'woshiduide'
          Enter password: *********
          Warning: single quotes were not trimmed from the password by your command
          line client, as you might have expected.

          而這個時候真正的密碼是'woshiduide'

          C:\>mysql -uroot -p'woshiduide'
          Welcome to the MySQL monitor.? Commands end with ; or \g.
          Your MySQL connection id is 18
          Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

          Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

          mysql>

          而新手往往這樣:
          C:\>mysql -uroot -pwoshiduide
          ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y
          ES)
          所以非常郁悶,BAIDU、GOOGLE的搜了一大堆。

          我現在把密碼改回去。
          C:\>mysqladmin -uroot -p'woshiduide' password 123456

          2、還有就是可以直接進入MYSQL,然后修改密碼。

          mysql> use mysql
          Database changed
          mysql> update user set PASSWORD = PASSWORD('woshiduide') where USER='root' and H
          OST='localhost';
          Query OK, 1 row affected (0.05 sec)
          Rows matched: 1? Changed: 1? Warnings: 0

          mysql> flush privileges;

          mysql> exit
          Bye

          C:\>mysql -uroot -pwoshiduide
          Welcome to the MySQL monitor.? Commands end with ; or \g.
          Your MySQL connection id is 23
          Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

          Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

          mysql>
          Query OK, 0 rows affected (0.02 sec)
          3、還有一種就是用SET PASSWORD 命令修改:

          C:\>mysql5.bat
          Enter password: ******
          Welcome to the MySQL monitor.? Commands end with ; or \g.
          Your MySQL connection id is 8
          Server version: 5.1.17-beta-community-nt-debug-log MySQL Community Server (GPL)

          Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

          mysql> set password for root@'localhost' = password('woshiduide');
          Query OK, 0 rows affected (0.02 sec)

          mysql> flush privileges;
          Query OK, 0 rows affected (0.09 sec)

          mysql> exit
          Bye
          4、GRANT 也可以,不過這里不介紹。因為涉及到權限的問題。

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


          網站導航:
           
          主站蜘蛛池模板: 安阳县| 肇源县| 东台市| 临泉县| 大埔县| 昆明市| 华阴市| 武鸣县| 远安县| 永嘉县| 古交市| 灵台县| 资兴市| 余姚市| 张掖市| 郧西县| 闸北区| 江陵县| 台东县| 松江区| 灵川县| 简阳市| 镇宁| 平谷区| 固镇县| 咸丰县| 固原市| 西丰县| 招远市| 汉寿县| 百色市| 阿勒泰市| 阜平县| 杨浦区| 酉阳| 延川县| 宜城市| 肇州县| 维西| 安康市| 昌乐县|