這篇文章主要講解了“怎么重置MySQL的root密碼以及設(shè)置mysql遠(yuǎn)程登陸權(quán)限”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么重置mysql的root密碼以及設(shè)置mysql遠(yuǎn)程登陸權(quán)限”吧!
成都創(chuàng)新互聯(lián)公司-成都網(wǎng)站建設(shè)公司,專(zhuān)注成都網(wǎng)站制作、成都做網(wǎng)站、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)、網(wǎng)站營(yíng)銷(xiāo)推廣,域名申請(qǐng),虛擬主機(jī),成都網(wǎng)站托管有關(guān)企業(yè)網(wǎng)站制作方案、改版、費(fèi)用等問(wèn)題,請(qǐng)聯(lián)系成都創(chuàng)新互聯(lián)公司。
root密碼忘記,重置mysql的root密碼:t
一、修改mysql的配置文件my.cnf
1.在[mysqld]的段中加上一句:skip-grant-tables
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
skip-grant-tables
保存并且退出vi。
(或執(zhí)行 mysqld_safe --skip-grant-tables &)
2.重新啟動(dòng)mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
3.登錄并修改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
mysql> update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() 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
4.將MySQL的登錄設(shè)置修改回來(lái)
# vi /etc/my.cnf
將剛才在[mysqld]的段中加上的skip-grant-tables刪除
保存并且退出vi。
5.重新啟動(dòng)mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
二、
停止mysql服務(wù)
/etc/init.d/mysqld stop
sudo mysqld_safe --skip-grant-table&
mysql
use mysql;
update user set password = password('yourpasswd') where user = 'root';
flush privileges;
重啟下mysql服務(wù)即可重新用新密碼登錄
/etc/init.d/mysqld restart
允許遠(yuǎn)程連接mysql
通過(guò)navicat連接MySQL的時(shí)候發(fā)生的這個(gè)錯(cuò)誤
ERROR 1130: Host ***.***.***.*** is not allowed to connect to this MySQL server
說(shuō)明所連接的用戶帳號(hào)沒(méi)有遠(yuǎn)程連接的權(quán)限,只能在本機(jī)(localhost)登錄。
需更改 MySQL 數(shù)據(jù)庫(kù)里的 user表里的 host項(xiàng)
把localhost改稱(chēng)%
一、
登陸到MySQL ,首先 use MySQL;
按照別人提供的方式update的時(shí)候,出現(xiàn)錯(cuò)誤。
MySQL> update user set host='%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
然后查看了下數(shù)據(jù)庫(kù)的host信息如下:
MySQL> select host from user where user = 'root';
+-----------------------+
| host |
+-----------------------+
| % |
| 127.0.0.1 |
| localhost.localdomain |
+-----------------------+
3 rows in set (0.00 sec)
host已經(jīng)有了%這個(gè)值,所以直接運(yùn)行命令:
MySQL>flush privileges;
二、
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> selectuser.host from user;
+-----------+--------------+
| user| host|
+-----------+--------------+
| root| %|
| root| 127.0.0.1|
| repl_user | 192.168.1.52 |
+-----------+--------------+
3 rows in set (0.00 sec)
允許指定IP訪問(wèn)mysql
mysql> grant all privileges on *.* to 'root'@116.224.126.250 identified by '123456';
QueryOK, 0 rows affected (0.00 sec)
感謝各位的閱讀,以上就是“怎么重置mysql的root密碼以及設(shè)置mysql遠(yuǎn)程登陸權(quán)限”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么重置mysql的root密碼以及設(shè)置mysql遠(yuǎn)程登陸權(quán)限這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!