如何修改Linux服務(wù)器中的MySQL數(shù)據(jù)庫(kù)密碼
修改Linux服務(wù)器中的MySQL數(shù)據(jù)庫(kù)密碼
1.知道m(xù)ysql的密碼情況下
通過登錄mysql系統(tǒng),
mysql -uroot -p Enter password: 【輸入原來的密碼】 mysql>use mysql;
查看下自己mysql的版本,注意不同的版本修改密碼的方式會(huì)有所不同
mysql>select version();
根據(jù)自己的版本從下面的方式中,選擇一種進(jìn)行修改密碼即可
5.7以前
mysql>update user set password=password(“123456”) where user=‘root';
5.7版本 user表沒有了password字段,要用authentication_string代替
mysql>update user set authentication_string=password(“123456”) where user=‘root';
8.0以上版本 注意密碼要有數(shù)字,大小寫字母,和特殊符號(hào),要不密碼會(huì)驗(yàn)證不通過
mysql>ALTER USER ‘root' IDENTIFIED BY ‘123456@Test';
刷新權(quán)限(必須步驟)
mysql> flush privileges; mysql> exit;
修改完后要記得重啟下mysql服務(wù),讓修改生效
service mysqld restart
2.不知道m(xù)ysql的密碼情況下
不知道m(xù)ysql密碼的情況下,在安全模式下啟動(dòng)mysql,不用輸入密碼就可以登錄進(jìn)去,&表示在后臺(tái)運(yùn)行,不再后臺(tái)運(yùn)行的話,就要再打開一個(gè)終端。
mysqld_safe --skip-grant-tables &
或者你可以
輸入:vi /etc/my.cnf 回車。在這個(gè)文件中的最后一行輸入:skip-grant-tables
然后重啟mysql服務(wù) service mysqld restart 進(jìn)入到安全模式,修改完密碼后記得再刪除掉這行數(shù)據(jù)重啟下
mysql -uroot -p
然后提示你輸入原密碼,安全模式下直接回車就可以進(jìn)入mysql數(shù)據(jù)庫(kù)了;
mysql>use mysql;
后面的步驟跟上面一樣了,根據(jù)自己的版本選擇修改方式
5.7以前
mysql>update user set password=password(“123456”) where user=‘root';
5.7版本 user表沒有了password字段,要用authentication_string代替
mysql>update user set authentication_string=password(“123456”) where user=‘root';
8.0以上版本 注意密碼要有數(shù)字,大小寫字母,和特殊符號(hào),要不密碼會(huì)驗(yàn)證不通過
mysql>ALTER USER ‘root' IDENTIFIED BY ‘123456@Test';
刷新權(quán)限(必須步驟)
mysql> flush privileges; mysql> exit;
修改完后要記得重啟下mysql服務(wù),讓修改生效
service mysqld restart
mysql5.7的密碼修改錯(cuò)誤問題:ERROR 1054 (42S22): Unknown column 'password' in 'field list'的解決
本意向修改一個(gè)用戶的密碼,網(wǎng)上搜到的命令為如下
mysql> update user set password=password(“新密碼”) where user=”用戶名”;
執(zhí)行后報(bào)錯(cuò):
ERROR 1054(42S22) Unknown column 'password' in ‘field list’
錯(cuò)誤的原因是 5.7版本下的mysql數(shù)據(jù)庫(kù)下已經(jīng)沒有password這個(gè)字段了,password字段改成了authentication_string
所以請(qǐng)使用一下命令:
E:\app\mysql\mysql-5.7.22-winx64\bin>mysql -uroot -pmysql123 # 先進(jìn)入數(shù)據(jù)庫(kù)
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql; # 使用mysql
Database changed
mysql> select User from user; # 此處為查詢用戶命令
+---------------+
| User |
+---------------+
| root |
| root |
| mysql.session |
| mysql.sys |
| root |
+---------------+
5 rows in set (0.01 sec)
mysql> update mysql.user set authentication_string=password('mysql') where user='root'; # 更新密碼
Query OK, 3 rows affected, 1 warning (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 1
mysql> flush privileges; # 數(shù)據(jù)刷新
Query OK, 0 rows affected (0.00 sec)
mysql> quit # 退出
Bye
E:\app\mysql\mysql-5.7.22-winx64\bin>mysql -uroot -pmysql # 再次進(jìn)入
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
跟我這樣設(shè)置,就可以了,大家自己設(shè)置自己的密碼就行
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解析在MySQL里創(chuàng)建外鍵時(shí)ERROR 1005的解決辦法
本篇文章是對(duì)在MySQL里創(chuàng)建外鍵時(shí)ERROR 1005的解決辦法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
MySQL中pt-table-checksum實(shí)現(xiàn)主從一致性校驗(yàn)的終極方案
pt-table-checksum 憑借低侵入性、高準(zhǔn)確性和良好的兼容性,成為 MySQL 主從一致性校驗(yàn)的首選工具,下面就來詳細(xì)的介紹一下MySQL中pt-table-checksum實(shí)現(xiàn)主從一致性校驗(yàn),感興趣的可以了解一下2026-04-04
MySQL server has gone away 問題的解決方法
MySQL server has gone away 問題解決方法,需要的朋友可以參考下。2010-06-06
與MSSQL對(duì)比學(xué)習(xí)MYSQL的心得(五)--運(yùn)算符
MYSQL中的運(yùn)算符很多,這一節(jié)主要講MYSQL中有的,而SQLSERVER沒有的運(yùn)算符2014-06-06
Windows下MySql錯(cuò)誤代碼1045的解決方法
這篇文章主要介紹了Windows下MySql錯(cuò)誤代碼1045的解決方法,文中還包含了2個(gè)Linux下的解決方法,需要的朋友可以參考下2014-06-06
簡(jiǎn)單講解sql語(yǔ)句中的group by的使用方法
掌握sql語(yǔ)句中g(shù)roup by的使用方法會(huì)對(duì)我們的工作效率有很大的提升,下面小編來和大家一起簡(jiǎn)單學(xué)習(xí)一下2019-05-05

