成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

MySQL單實(shí)例重置密碼的兩種方法

MySQL單實(shí)例重置密碼的兩種方法

網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了開化免費(fèi)建站歡迎大家使用!


在工作學(xué)習(xí)中,我們有時會忘記數(shù)據(jù)庫的密碼,下面是MySQL單實(shí)例密碼重置的步驟。

說明:

(1)[root@mysql1 ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

(2)[root@mysql1 ~]# mysql --version

mysql  Ver 14.14 Distrib 5.7.13, for Linux (i686) using  EditLine wrapper

主要步驟如下:

  1. 首先停止MySQL

    [root@mysql1 ~]# /etc/init.d/mysqld stop

    /etc/init.d/mysqld: line 46: /usr/local/mysql: is a directory

    /etc/init.d/mysqld: line 47: /usr/local/mysql/data: is a directory

    Shutting down MySQL. SUCCESS!

    查看MySQL的狀態(tài):

    [root@mysql1 ~]# /etc/init.d/mysqld status

    /etc/init.d/mysqld: line 46: /usr/local/mysql: is a directory

    /etc/init.d/mysqld: line 47: /usr/local/mysql/data: is a directory

     ERROR! MySQL is not running

    查看MySQL的進(jìn)程:

    [root@mysql1 ~]# ps aux|grep mysql|grep -v grep

  2. 使用--skip-grant-tables啟用MySQL忽略登入授權(quán)驗(yàn)證

    [root@mysql1 ~]# mysqld_safe --skip-grant-tables --user=mysql &

    [1] 6559

    [root@mysql1 ~]# 2017-07-30T14:23:38.600285Z mysqld_safe Logging to '/usr/local/mysql/data/mysqld.err'.

    2017-07-30T14:23:38.640326Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

  3. 無需密碼即可登入MySQL

    [root@mysql1 ~]# mysql

    MySQL單實(shí)例重置密碼的兩種方法

  4. 重置root密碼

    說明:新安裝的MySQL5.7,登錄時提示密碼錯誤,安裝的時候并沒有更改密碼,后來通過免密碼登錄的方式更改密碼,輸入update mysql.user set password=password('wtf123') where user='root' and host='localhost'時提示ERROR 1054 (42S22): Unknown column 'password' in 'field list',原來是mysql5.7數(shù)據(jù)庫下已經(jīng)沒有password這個字段了,password字段改成了authentication_string.

    mysql> update mysql.user set authentication_string=password('wtf123') where user='root’and host='localhost';

    Query OK, 1 row affected, 1 warning (0.00 sec)

    Rows matched: 1  Changed: 1  Warnings: 1

    MySQL單實(shí)例重置密碼的兩種方法

    刷新:mysql> flush privileges;

    退出:mysql> quit

    說明:不能使用set password=password('wtf1234');

    MySQL單實(shí)例重置密碼的兩種方法

  5. 重啟服務(wù)再登入

    [root@mysql1 ~]# /etc/init.d/mysqld restart

    [root@mysql1 ~]# mysql -uroot -pwtf123

    說明:查看數(shù)據(jù)庫密碼命令:

    mysql> select user,host,authentication_string from mysql.user;

    MySQL單實(shí)例重置密碼的兩種方法

擴(kuò)展:通過修改/etc/my.cnf 配置文件來重置mysql密碼

1.打開mysql的配置文件,命令:vim /etc/my.cnf 。在配置文件中新增一行 skip-grant-tables,結(jié)果如下圖所示:

MySQL單實(shí)例重置密碼的兩種方法

2.保存并退出!

3.重啟mysqld,命令:service mysqld restart 

4.無需密碼即可登入MySQL

 [root@mysql1 ~]# mysql

  mysql> update mysql.user set authentication_string=password('123456') where        user='root’and host='localhost';

 flush privileges; #刷新權(quán)限

MySQL單實(shí)例重置密碼的兩種方法

退出:quit

5.退出后還原my.cnf重啟,命令如下:

vim /etc/my.cnf  #打開mysql配置文件,將skip-grant-tables前面加#;

/etc/init.d/mysqld restart  #重新啟動mysql;

用新密碼登入mysql數(shù)據(jù)庫,命令如下:

#mysql –uroot –p123456 即可正常登入數(shù)據(jù)庫了!

分享題目:MySQL單實(shí)例重置密碼的兩種方法
網(wǎng)站鏈接:http://jinyejixie.com/article44/ppjdhe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、標(biāo)簽優(yōu)化全網(wǎng)營銷推廣、響應(yīng)式網(wǎng)站App開發(fā)、軟件開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司