电竞比分网-中国电竞赛事及体育赛事平台

分享

linux下mysql 5.7及以前版本 root密碼修改方法【轉(zhuǎn)】

 JhouShuai 2017-09-19

 1.首先確認服務(wù)器出于安全的狀態(tài),也就是沒有人能夠任意地連接MySQL數(shù)據(jù)庫。 
因為在重新設(shè)置MySQL的root密碼的期間,MySQL數(shù)據(jù)庫完全出于沒有密碼保護的 
狀態(tài)下,其他的用戶也可以任意地登錄和修改MySQL的信息??梢圆捎脤ySQL對 
外的端口封閉,并且停止Apache以及所有的用戶進程的方法實現(xiàn)服務(wù)器的準(zhǔn)安全 
狀態(tài)。最安全的狀態(tài)是到服務(wù)器的Console上面操作,并且拔掉網(wǎng)線。 
2.修改MySQL的登錄設(shè)置: 
# vi /etc/my.cnf 
在[mysqld]的段中加上一句:skip-grant-tables 
例如: 
[mysqld] 
datadir=/var/lib/mysql 
socket=/var/lib/mysql/mysql.sock 
skip-grant-tables 
保存并且退出vi。 
3.重新啟動mysqld 
# /etc/init.d/mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ] 
4.登錄并修改MySQL的root密碼 
# /usr/bin/mysql 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 3 to server version: 3.23.56 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 
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

5、修改密碼

Mysql 5.6及以前版本:

i、

mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ; 
Query OK, 0 rows affected (0.00 sec) 

Rows matched: 2 Changed: 0 Warnings: 0 
mysql> flush privileges ; 
Query OK, 0 rows affected (0.01 sec) 
mysql> quit 
Bye

ii、將MySQL的登錄設(shè)置修改回來 
# vi /etc/my.cnf 
將剛才在[mysqld]的段中加上的skip-grant-tables刪除 
保存并且退出vi。 
iii、重新啟動mysqld 
# /etc/init.d/mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ]

Mysql 5.7版本:

i、mysql> UPDATE user SET authentication_string = password ( 'new-password' ) WHERE User = 'root' ; 
Query OK, 0 rows affected (0.00 sec) 

ii、將配置文件my.cnf 中 skip-grant-tables 注釋掉,重啟 mysql

iii、使用第一步設(shè)置的密碼登錄mysql,再次修改密碼:

mysql> set password = password('xxxxxxxx'); (新密碼必須包含大小寫字母,特殊字符,數(shù)字)

mysql> flush privileges ; 

Query OK, 0 rows affected (0.01 sec) 

mysql> quit 

Bye


原文地址:http://blog.csdn.net/dszgf5717/article/details/46850471

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多