MySQL修改密碼方法匯總
MySQL5.7版本之前修改密碼的方法:
方法1: 用SET PASSWORD命令
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
方法2:用mysqladmin
mysqladmin -u root password "newpass"
如果root已經(jīng)設(shè)置過密碼,采用如下方法
mysqladmin -u root password oldpass "newpass"
方法3: 用UPDATE直接編輯user表
[root@ ~]#mysql -uroot -p
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
在丟失root密碼的時候,可以這樣
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;
MySQL 5.7.22修改密碼的方式如下:
1,版本更新,原來user里的password字段已經(jīng)變更為authentication_string版本更新 緣故,好多網(wǎng)上的教程都不適用了,甚至連官網(wǎng)的文檔也不是能夠順利操作的。如果 MySQL 正在運行,首先殺之:killall -TERM mysqld。運行mysqld_safe --skip-grant-tables &如果此時不想被遠程連接:mysqld_safe --skip-grant-tables --skip-networking &使用mysql連接server更改密碼
mysql> update mysql.user set authentication_string=password('hwg123') where user='root' and Host = 'localhost';
mysql> exit
[root@Centos7_3 ~]# systemctl restart mysqld
*特別提醒注意的一點是,新版的mysql數(shù)據(jù)庫下的user表中已經(jīng)沒有Password字段了
而是將加密后的用戶密碼存儲于authentication_string字段。
2,升級mysql報錯如下:ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 45, found 42. Created with MySQL 50556, now running 50722. Please use mysql_upgrade to fix this error.錯誤是由于你曾經(jīng)升級過數(shù)據(jù)庫,升級完后沒有使用mysql_upgrade升級數(shù)據(jù)結(jié)構(gòu)造成的。
解決辦法:使用mysql_upgrade命令
root@localhost ~]# mysql_upgrade -u root -phwg123
3,MySQL5.7.22數(shù)據(jù)庫安裝完后更改密碼;
[root@ ~]# cat /var/log/mysqld.log | grep password
[root@ ~]# mysql -uroot -pRir.*sJUX6M*
進入mysql后需要改全局變量。要不然你設(shè)置的密碼要符合密碼復雜度。
mysql> set global validate_password_policy=0;
[root@zabbixserver ~]# systemctl restart mysqld
[root@zabbixserver ~]# mysql -uroot -pRir.*sJUX6M*
mysql> ALTER USER USER() IDENTIFIED BY '12345678';
或者是這個樣子:
mysql> ALTER USER USER() IDENTIFIED BY 'Pass123!';
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信