Pre-requisites:
A system with CentOS Stream 9 installed and running
Access to a terminal or command line
Root or sudo privileges
MySQL 8.0
In this guide, we will show you how to how to setup a user account and access a MySQL server remotely on a Linux system.
You will need to open MySQL's default port 3306 to allow traffic to MySQL
Open port
firewall-cmd --permanent --zone=public --add-port=3306/tcp
Reload the firewall to apply the changes and make the newly opened port accessible
firewall-cmd --reload
Firewalld doesn't automatically update its rules until you explicitly reload it
List open ports
firewall-cmd --zone=public --list-ports
The telnet command allows you to check if the port is opened for communication. If the connection is successful, you see the message: Connected to <host_IP>. If the connection fails, you see the message: Unable to connect to remote host.
The syntax for using the "telnet" command to connect to a specific host and port is:
telnet [host_address] [port_number]
"host_address" is the IP of the server you want to connect to
"port_number" is the specific port you want to access on that server
Show MySQL users and hosts they are allowed to connect from:
select user, host from mysql.user;
Grant all privileges to user in MySQL 8.0
CREATE USER 'user'@'localhost' IDENTIFIED BY 'PASSWORD'; GRANT ALL ON *.* TO 'user'@'ip_address'; FLUSH PRIVILEGES;
Make sure to replace "ip_address" with the specific IP address you want to allow connections from.