WAMP安裝好后,mysql密碼是為空的,那么要如何修改呢?其實很簡單,通過幾條指令就行了,下面我就一步步來操作。
首先,通過WAMP打開mysql控制台。
提示輸入密碼,因為現在是空,所以直接按回車。
然后輸入“use mysql”,意思是使用mysql這個數據庫,提示“Database changed”就行。
然后輸入要修改的密碼的sql語句“update user set password=PASSWORD('hooray') where user='root';”,注意,sql語句結尾的分號不能少,提示什么什么OK就行了。
最后輸入“flush privileges;”,不輸入這個的話,修改密碼的操作不會生效的。
然后輸入“quit”退出。
又一次下載安裝時,修改mysql密碼報錯 的解決方法
新安裝的MySQL5.7,登錄時提示密碼錯誤,安裝的時候並沒有更改密碼,后來通過免密碼登錄的方式更改密碼,輸入update mysql.user set password=password('root') where user='root'時提示ERROR 1054 (42S22): Unknown column 'password' in 'field list',原來是mysql數據庫下已經沒有password這個字段了,password字段改成了
authentication_string
所以更改語句替換為update mysql.user set authentication_string=password('root') where user='root' ;即可
我的系統版本如下:
完整的更改MySQL密碼的方式如下:
1、vim /etc/my.cnf 加入skip-grant-tables
2、重啟MySQL, /etc/init.d/mysqld restart
3、終端輸入 mysql 直接登錄MySQL數據庫,然后use mysql
4、update mysql.user set authentication_string=password('root') where user='root' ;
5、編輯my.cnf文件刪掉skip-grant-tables 這一行,然后重啟MySQL,/etc/init.d/mysqld restart,否則MySQL仍能免密碼登錄
6、mysql -u root -p
然后輸入密碼即可登錄MySQL數據庫