最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL 5.7忘記root密碼后修改的詳細(xì)教程

 更新時間:2017年05月07日 15:02:39   作者:瀟湘隱者  
因為長時間不操作mysql而忘記root密碼的朋友估計不在少數(shù),最近發(fā)現(xiàn)在MySQL 5.7版本下用之前的方法修改密碼不能成功了,所以只能重新想辦法解決,下面這篇文章主要給大家介紹了MySQL 5.7忘記root密碼后修改的詳細(xì)教程,需要的朋友可以參考。

前言

一直以來,MySQL的應(yīng)用和學(xué)習(xí)環(huán)境都是MySQL 5.6和之前的版本,也沒有去關(guān)注新版本MySQL 5.7的變化和新特性。今天幫人處理忘記root密碼的時時候,發(fā)現(xiàn)以前的方法不奏效了。

具體情況如下所示:

案例環(huán)境如下:

        操作系統(tǒng) : Red Hat Enterprise Linux Server release 6.6 (Santiago)

        數(shù)據(jù)庫版本: 5.7.18 MySQL Community Server (GPL)

忘記密碼,輸入錯誤的密碼時遇到下面錯誤信息:

[root@mytestlnx02 ~]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@mytestlnx02 ~]#

檢查MySQL服務(wù)是否啟動,如果啟動,關(guān)閉MySQL服務(wù)

[root@mytestlnx02 ~]# ps -ef | grep -i mysql
root  22972  1 0 14:18 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 23166 22972 0 14:18 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root  23237 21825 0 14:22 pts/0 00:00:00 grep -i mysql
[root@mytestlnx02 ~]# service mysqld stop
Stopping mysqld: [ OK ]
[root@mytestlnx02 ~]# 

找到MySQL的my.cnf配置文件,在/etc/my.cnf (有些版本是/etc/mysql/my.cnf)在里面增加下面一段信息:

[mysqld] 

skip-grant-tables 

然后啟動MySQL,進(jìn)入MySQL后,修改root密碼,操作過程中遇到ERROR 1054 (42S22): Unknown column 'password' in 'field list',查了一下user表的表結(jié)構(gòu),發(fā)現(xiàn)原來MySQL 5.7下,user表已經(jīng)沒有Password字段。加密后的用戶密碼存儲于authentication_string字段。

具體操作過程如下所示:

[root@mytestlnx02 ~]# service mysqld start
Starting mysqld: [ OK ]
[root@mytestlnx02 ~]# mysql -u root 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2017, 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;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> update user set password=PASSWORD('Kd8k&dfdl023')
 -> where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update mysql.user set authentication_string=password('Kd8k&dfdl023') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit

在my.cnf文件中,把剛才加入的那一行“skip-grant-tables”注釋或刪除掉。 然后重啟MySQL服務(wù)后需要執(zhí)行命令set password=password('newpassword');后,問題搞定。

[root@mytestlnx02 ~]# service mysqld start
Starting mysqld: [ OK ]
[root@mytestlnx02 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18
 
Copyright (c) 2000, 2017, 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;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password=password('Kd8k&dfdl023');
Query OK, 0 rows affected, 1 warning (0.00 sec)

后面查詢了一下相關(guān)資料,發(fā)現(xiàn)MySQL 5.7在安全方面有下一些新特性。

1. 用戶表 mysql.user 的 plugin字段不允許為空, 默認(rèn)值是 mysql_native_password,而不是 mysql_old_password,不再支持舊密碼格式;

2. 增加密碼過期機制,過期后需要修改密碼,否則可能會被禁用,或者進(jìn)入沙箱模式; 是否啟用密碼過期由參數(shù)default_password_lifetime控制。

mysql> show variables like 'default_password_lifetime';
+---------------------------+-------+
| Variable_name    | Value |
+---------------------------+-------+
| default_password_lifetime | 0  |
+---------------------------+-------+
1 row in set (0.00 sec)
 
mysql>

3:增加了密碼安全等級以及密碼復(fù)雜度設(shè)置。參數(shù)如下:

mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name      | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file |  |
| validate_password_length    | 8  |
| validate_password_mixed_case_count | 1  |
| validate_password_number_count  | 1  |
| validate_password_policy    | MEDIUM |
| validate_password_special_char_count | 1  |
+--------------------------------------+--------+
7 rows in set (0.00 sec)

4. 使用 mysql_install_db 初始化時,默認(rèn)會自動生成隨機密碼,隨機密碼放在/var/log/mysqld.log中,并且不創(chuàng)建除 root@localhost和mysql.sys@localhost 外的其他賬號,也不創(chuàng)建 test 庫;

[root@mytestlnx02 mysql]# yum localinstall mysql-community-{server,client,common,libs}-* 
[root@mytestlnx02 mysql]# rpm -qa | grep -i mysql
mysql-community-client-5.7.18-1.el6.i686
mysql-community-libs-5.7.18-1.el6.i686
perl-DBD-MySQL-4.013-3.el6.x86_64
mysql-community-server-5.7.18-1.el6.i686
mysql-community-common-5.7.18-1.el6.i686
mysql-community-libs-compat-5.7.18-1.el6.i686
[root@mytestlnx02 mysql]# service mysqld start
 
Initializing MySQL database: [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld: [ OK ]
[root@mytestlnx02 mysql]# 
[root@mytestlnx02 mysql]# grep 'temporary password' /var/log/mysqld.log
2017-05-05T06:10:57.802143Z 1 [Note] A temporary password is generated for root@localhost: w99s(m-q_ML:
 
mysql> select user ,host from user;
+-----------+-----------+
| user  | host  |
+-----------+-----------+
| mysql.sys | localhost |
| root  | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

  • MySQL運維實戰(zhàn)使用RPM進(jìn)行安裝部署

    MySQL運維實戰(zhàn)使用RPM進(jìn)行安裝部署

    這篇文章主要為大家介紹了MySQL運維實戰(zhàn)使用RPM進(jìn)行安裝部署實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12
  • Mysql將查詢結(jié)果集轉(zhuǎn)換為JSON數(shù)據(jù)的實例代碼

    Mysql將查詢結(jié)果集轉(zhuǎn)換為JSON數(shù)據(jù)的實例代碼

    這篇文章主要介紹了Mysql將查詢結(jié)果集轉(zhuǎn)換為JSON數(shù)據(jù)的實例代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03
  • mysql分頁性能探索

    mysql分頁性能探索

    本文帶領(lǐng)大家一起探討mysql分頁性能,需要的朋友一起看看吧
    2017-10-10
  • MySQL Left JOIN時指定NULL列返回特定值詳解

    MySQL Left JOIN時指定NULL列返回特定值詳解

    我們有時會有這樣的應(yīng)用,需要在sql的left join時,需要使值為NULL的列不返回NULL而時某個特定的值,比如0。這個時候,用is_null(field,0)是行不通的,會報錯的,可以用ifnull實現(xiàn),但是COALESE似乎更符合標(biāo)準(zhǔn)
    2013-07-07
  • MySQL中JOIN連接的基本用法實例

    MySQL中JOIN連接的基本用法實例

    大家對join應(yīng)該都不會陌生,join可以將兩個表連接起來,下面這篇文章主要給大家介紹了關(guān)于MySQL中JOIN連接用法的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • 讓MySQL中某個表的操作不生成binlog日志的問題解決

    讓MySQL中某個表的操作不生成binlog日志的問題解決

    文章介紹了四種方法讓MySQL中某個表的操作不生成binlog日志:會話級臨時關(guān)閉binlog、通過復(fù)制過濾規(guī)則、調(diào)整binlog格式和全局禁用binlog,每種方法都有其適用場景和局限性,建議優(yōu)先使用會話級臨時關(guān)閉方法,并根據(jù)具體需求選擇合適的方案,感興趣的朋友跟隨小編一起看看吧
    2025-03-03
  • MySQL中UNION與UNION ALL的基本使用方法

    MySQL中UNION與UNION ALL的基本使用方法

    這篇文章主要給大家介紹了關(guān)于MySQL中UNION與UNION ALL的基本使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用MySQL具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Mysql實戰(zhàn)練習(xí)之簡單圖書管理系統(tǒng)

    Mysql實戰(zhàn)練習(xí)之簡單圖書管理系統(tǒng)

    由于課設(shè)需要做這個,于是就抽了點閑余時間,寫了下,用Mysql與Java,基本全部都涉及到,包括借書/還書,以及書籍信息的更新,查看所有的書籍。需要的朋友可以參考下
    2021-09-09
  • SQL中distinct去重關(guān)鍵字使用和count統(tǒng)計組合使用方法

    SQL中distinct去重關(guān)鍵字使用和count統(tǒng)計組合使用方法

    這篇文章主要給大家介紹了關(guān)于SQL中distinct去重關(guān)鍵字使用和count統(tǒng)計組合使用的相關(guān)資料,count()是SQL中提供的用于統(tǒng)計記錄數(shù)量的函數(shù),需要的朋友可以參考下
    2024-08-08
  • MySql索引使用策略分析

    MySql索引使用策略分析

    這篇文章主要介紹了MySql索引使用策略分析,幫助大家更好的理解和使用MySQL,感興趣的朋友可以了解下
    2020-11-11

最新評論

朔州市| 车致| 宜黄县| 门头沟区| 宁强县| 饶阳县| 卢湾区| 无锡市| 南陵县| 泰安市| 西华县| 无棣县| 平舆县| 锡林郭勒盟| 城口县| 南岸区| 武冈市| 鸡西市| 奈曼旗| 科尔| 资中县| 东平县| 丹东市| 昌吉市| 师宗县| 县级市| 吉隆县| 临澧县| 凤城市| 沅陵县| 武邑县| 黄冈市| 天气| 延川县| 鹤山市| 锡林郭勒盟| 渭源县| 鹤壁市| 雷山县| 瑞昌市| 枣强县|