Mysql5.7如何修改root密碼
2017-06-14 08:08:06
16926
版本更新,原來user里的password字段已經(jīng)變更為authentication_string
版本更新 緣故,好多網(wǎng)上的教程都不適用了,甚至連官網(wǎng)的文檔也不是能夠順利操作的。
如果 MySQL 正在運(yùn)行,首先殺之:
killall -TERM mysqld。
運(yùn)行
mysqld_safe --skip-grant-tables &
如果此時(shí)不想被遠(yuǎn)程連接:
mysqld_safe --skip-grant-tables --skip-networking &
使用mysql連接server
更改密碼:
update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
*特別提醒注意的一點(diǎn)是,新版的mysql數(shù)據(jù)庫下的user表中已經(jīng)沒有Password字段了
而是將加密后的用戶密碼存儲(chǔ)于authentication_string字段
mysql> flush privileges;
mysql> quit;
修改完畢。重啟
killall -TERM mysqld。
mysqld_safe &
然后mysql就可以連接了
但是此時(shí)操作似乎功能不完全,還要alter user...
alter user 'root'@'localhost' identified by '123';
網(wǎng)文說也可以:
set password for 'root'@'localhost'=password('123');
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql