mysql 5.7 root密碼重置(centos 7)
mysql5.7版本之後,與mariadb不同,在安裝之後,在啟動之時,會進行自動隨機密碼的設定,所以在systemctl start mysqld
之後,會出現mysql -uroot -p
無法登陸的情況
實際上mysqld在啟動時,會自動設定root密碼的,可以在其相關日誌裡面查看到,如下:
[root@bogon ~]# grep password /var/log/mysqld.log
2017-07-31T10:31:57.368883Z 1 [Note] A temporary password is generated for root@localhost: TjcrBm.j,7eU
2017-07-31T10:32:30.201882Z 3 [Note] Access denied for user "root"@"localhost" (using password: NO)
2017-07-31T10:34:40.233539Z 0 [Note] Shutting down plugin "validate_password"
2017-07-31T10:34:41.483983Z 0 [Note] Shutting down plugin "sha256_password"
2017-07-31T10:34:41.483990Z 0 [Note] Shutting down plugin "mysql_native_password"
mysql root的初始密碼為TjcrBm.j,7eU(每人情況不一樣,具體值在mysql日誌中查看)
mysql密碼重置
當然有些人可能是root密碼真忘記了,那樣可以通過mysql免密碼登陸
在其配置文件/etc/my.cnf中加入skip-grant-tables=1即可
[root@bogon ~]# grep -v ^# /etc/my.cnf | grep -v ^$
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip-grant-tables=1
然後重啟mysql,使用mysql
命令即可進入
[root@bogon ~]# systemctl restart mysqld
[root@bogon ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@bogon ~]# mysql
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 4
Server version: 5.7.19
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>
修改mysql root密碼
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 authentication_string = password("123456") 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)
然後將/etc/my.cnf中的skip-grant-tables=1
注釋掉,重啟mysql服務即可。
在此要注意的是,之前版本密碼修改欄位為password,在5.7版本之後欄位為authentication_string
mysql密碼難度修改mysql密碼修改為123456之後,有人發現使用123456能進入mysql,但是卻不能使用mysql的任何功能。會出現如下情況:
[root@bogon ~]# mysql -uroot -p123456
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 4
Server version: 5.7.19
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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
實際上,在初始更改root密碼時,並不能直接使用update來更改,需要使用alter user命令來更改
mysql> alter user "root"@"localhost" identified by "123456";
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
## mysql在5.7版本中加了密碼安全等級,弱密碼不能使用
mysql> alter user "root"@"localhost" identified by "QWEqwe123!@#";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql 安全策略以及root密碼清空
在上述修改密碼之後,可查看mysql的密碼安全策略
[root@bogon ~]# mysql -uroot -p"QWEqwe123!@#"
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 6
Server version: 5.7.19 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> show variables like "%password%";
+---------------------------------------+--------+
| Variable_name | Value |
+---------------------------------------+--------+
| default_password_lifetime | 0 |
| disconnect_on_expired_password | ON |
| log_builtin_as_identified_by_password | OFF |
| mysql_native_password_proxy_users | OFF |
| old_passwords | 0 |
| report_password | |
| sha256_password_proxy_users | OFF |
| 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 |
+---------------------------------------+--------+
14 rows in set (0.00 sec)


※node調用phantomjs-node爬取複雜頁面
※關於canvas畫布使用fillRect()時高度出現雙倍效果解決辦法
※Eclipse中安裝MemoryAnalyzer插件及使用
※用Eclipse生成JPA元模型
※SQL Server Alwayson創建代理作業注意事項
TAG:達人科技 |
※在Exchange Server中重置用戶密碼
※「Shopify小白系列」Shopify賬戶忘記密碼怎麼辦?Shopify密碼重置&應用介紹
※centos7重置密碼、單用戶模式、救援模式、ls命令、chmod命令
※CentOS7 重置 MySQL 8.0 密碼
※如何在Win10中重置和註銷Linux子系統
※看我如何發現Facebook密碼重置漏洞獲得$15000賞金(附POC)
※谷歌挖出 iMessage 新漏洞,運行舊系統的 iPhone 只能重置修復
※如何重置或恢復Windows SYSKEY密碼
※你的《荒野大鏢客Online》Beta進度應該不會被R星重置
※centos系統重置資料庫密碼圖文
※微軟官方確認:Windows 10將加入雲下載重置功能
※在 5 分鐘內重置丟失的 root 密碼
※《夢幻模擬戰1+2》重置版即將登陸PS4和Switch平台
※Windows 10 19H1新版18312推送:預留存儲上線、重置UI調整
※iOS11越獄必備救命工具,瞬間重置Cydia!
※《生存者同盟》HD重置 今秋登陸PS4,Switch及PC
※狂熱粉絲泄露 《骷髏騎士MediEvil》重置版近期登陸PS4平台
※MacBook開始卡了?重置SMC能幫到你
※微軟確認新的Windows 10累積更新問題 建議完全重置系統
※教你如何重置Mac的SMC和PRAM/NVRAM