본문 바로가기

DB/Mysql

[mysql] mysql 8.0 외부접속 허용 (계정생성)

728x90
반응형

1. 신규 계정 생성 

use mysql;

create user '계정명'@'%' identified by '비밀번호';

select user, host from user;

mysql> select user, host from user;

+------------------+-----------+

| user             | host      |

+------------------+-----------+

| 계정멍           | %         |

| mysql.infoschema | localhost |

| mysql.session    | localhost |

| mysql.sys        | localhost |

| root             | localhost |

+------------------+-----------+

5 rows in set (0.00 sec)

 

2. 권한부여 

mysql> GRANT ALL PRIVILEGES ON *.* TO '계정명'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

 

3. 경우에 따라 서버에서 iptables 정보를 반영해줘야 할 수 있으므로 참고하여 반영 

 ~]# iptables -A INPUT -p tcp --dport 3306 -j ACCEPT

 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
f2b-VSFTPD  tcp  --  anywhere             anywhere             tcp dpt:ftp
f2b-SSH    tcp  --  anywhere             anywhere             tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:webcache
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:mysql

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain f2b-SSH (1 references)
target     prot opt source               destination         
REJECT     all  --  120.48.64.201        anywhere             reject-with icmp-port-unreachable
RETURN     all  --  anywhere             anywhere            

Chain f2b-VSFTPD (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            
[root@yesltz ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
 ~]# systemctl restart iptables
728x90
반응형