連接mysql數據庫,報錯ERROR 1045 (28000)和ERROR 1698 (28000)問題

執行 mysql -uroot -p
報錯:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
原因:安裝完mysql的時候沒有設置密碼
解決原因:

           1.linux系統--->找到 my.conf文件(vim /etc/mysql/my.cnf)
              windows系統--->找到my.ini
            2.添加 
            [mysqld]
            skip-grant-tables   # 這個內容是跳過驗證,直接進入mysql
            3.保存修改信息,重啓mysql
            重啓命令:
            service mysql restart   
            4.進入mysql
            mysql 
            5.執行更改密碼命令
              mysql> use mysql;
              -----------------------------------------  
              修改密碼部分:
              mysql> update user set password=password('你的新密碼') where user='root' and host='localhost';  
              或者
              mysql> update mysql.user set authentication_string=password('你的新密碼') where user='root' and Host = 'localhost';
              注意:新版的mysql數據庫下的user表中已經沒有Password字段了,而是將加密後的用戶密碼存儲於authentication_string字段
              -----------------------------------------
              mysql> flush privileges; 
              mysql>quit
            6.將MySQL配置文件中的修改內容還原
              註釋掉
              skip-grant-tables
              
報錯:ERROR 1698 (28000): Access denied for user 'root'@'localhost' --->使用普通用戶登錄的時候會出現這種錯誤
原因是:root的plugin被修改成了auth_socket,用密碼登陸的plugin應該是mysql_native_password
解決方法:進入mysql
        mysql>use mysql;
        mysql>update mysql.user set plugin='mysql_native_password' where user='root';
        重啓mysql服務器
        service mysql restart

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章