mysql重設密碼及容許遠程訪問

一.重設密碼

1.知道原來的myql的root的密碼

方法一:

經過登陸mysql系統,
mysql -uroot -p
Enter password: 【輸入原來的密碼】
mysql>use mysql;
mysql> update user set authentication_string=passworD("test123") wher user='root';
mysql> flush privileges;
mysql> exit;

方法二:

在mysql系統外,使用mysqladmin
mysqladmin -u root -p password "test123"
Enter password: 【輸入原來的密碼】

2.不知道原來的myql的root的密碼

①.跳過密碼啓動

mysqld_safe --skip-grant-tables &html

②.重設密碼

# 直接輸入mysql,進入mysql
mysql
mysql> use mysql;
mysql> UPDATE user SET authentication_string=password("test123") WHERE user='root';   
mysql> flush privileges;
mysql> exit;

③.從新啓動mysql

systemctl restart mysqlmysql

二.容許外部訪問

1.設置容許訪問

# password是數據庫密碼
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

FLUSH PRIVILEGES;

2.使用navicat檢測一下,若是仍是不能鏈接,多是防火牆限制了。須要在防火牆裏面加開放數據庫端口的規則。先查看一下目前的防火牆,此時沒有放開3306端口!

firewall-cmd --list-allsql

[root@iZhp3di673f3rx1g5d9dfdZ soft]# firewall-cmd --list-all 
public
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client ssh
  ports: 20/tcp 21/tcp 22/tcp 80/tcp 8888/tcp 39000-40000/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:

3.開放3306端口

firewall-cmd --permanent --add-port=3306/tcpshell

4.重啓防火牆

service firewalld restart數據庫

5.查看3306端口是否開放

firewall-cmd --query-port=3306/tcpssh

[root@iZhp3di673f3rx1g5d9dfdZ soft]# firewall-cmd --query-port=3306/tcp
yes

6.再次查看如今防火牆

firewall-cmd --list-alltcp

[root@iZhp3di673f3rx1g5d9dfdZ soft]# firewall-cmd --list-all 
public
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client ssh
  ports: 20/tcp 21/tcp 22/tcp 80/tcp 8888/tcp 39000-40000/tcp 3306/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:

7.此時就能夠遠程鏈接了

站在巨人肩膀上摘蘋果

https://blog.csdn.net/qq_35070711/article/details/70860014.net

https://www.cnblogs.com/yybrhr/p/9810375.html3d

相關文章
相關標籤/搜索