隨筆-159  評論-114  文章-7  trackbacks-0
          適用的情況:1 忘記密碼
                      2 error 1045:Access denied for user 'root'@'localhost' (using password: Yes/No)
                      3 沒有權限Access denied for user ''@'localhost' to database
          步驟:
          1 停止mysql進程;
            windows:控制面板-管理工具-服務-mysql停止;
            linux:mysql stop;
          2 windows: mysqld --skip-grant-tables
            linux:mysqld_safe --skip-grant-tables
          3 重新打開一個命令行窗口,輸入
            mysql;進入mysql命令行
            use mysql;
            update user set password=password("new_pass") where user="root";修改密碼
            flush privileges; 刷新權限

          如果是MySQL 5.1 ,注意是  update user set password=old_password("new_pass") where user = "root"
          select length(password) from user where user='root';不是41就對了





          4 殺掉mysqld進程[任務管理器],重新啟動mysql。
            windows:控制面板-管理工具-服務-mysql啟動;
            linux:mysql start;











          我的系統是ubuntu6.06,最近新裝好的mysql在進入mysql工具時,總是有錯誤提示:
          # mysql -uroot -p
          Enter password:
          ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

          使用網上介紹的方法修改root用戶的密碼:
          # mysqladmin -uroot -p password 'newpassword'
          Enter password:
          mysqladmin: connect to server at 'localhost' failed
          error: 'Access denied for user 'root'@'localhost' (using password: YES)'

          現在終于被我找到了解決方法,如下(請先測試方法三,謝謝!):
          方法一:
          # /etc/init.d/mysql stop
          # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
          # mysql -u root mysql
          mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
          mysql> FLUSH PRIVILEGES;
          mysql> quit

          # /etc/init.d/mysql restart
          # mysql -uroot -p
          Enter password: <輸入新設的密碼newpassword>

          mysql>


          方法二:
          直接使用/etc/mysql/debian.cnf文件中[client]節提供的用戶名和密碼:
          # mysql -udebian-sys-maint -p
          Enter password: <輸入[client]節的密碼>
          mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
          mysql> FLUSH PRIVILEGES;
          mysql> quit

          # mysql -uroot -p
          Enter password: <輸入新設的密碼newpassword>

          mysql>


          方法三:
          這種方法我沒有進行過測試,因為我的root用戶默認密碼已經被我修改過了,那位有空測試一下,把結果告訴我,謝謝!!
          # mysql -uroot -p
          Enter password: <輸入/etc/mysql/debian.cnf文件中[client]節提供的密碼>

          至此,困惑多時的問題解決了!


          posted on 2010-04-08 15:56 北國狼人的BloG 閱讀(253) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 大同市| 青河县| 宜春市| 邮箱| 定西市| 依兰县| 宜州市| 边坝县| 西昌市| 深水埗区| 马边| 济源市| 封丘县| 都昌县| 安西县| 阳西县| 龙南县| 门头沟区| 新密市| 保亭| 常宁市| 文安县| 南丹县| 金昌市| 松原市| 钦州市| 兴和县| 深圳市| 米林县| 多伦县| 阿拉善左旗| 裕民县| 曲水县| 司法| 娄烦县| 侯马市| 河津市| 页游| 金堂县| 蒙自县| 海阳市|