-
Spin up two Linux-based virtual servers (EC2 instances in AWS) and name them:
mysql serverandmysql clientrespectively. -
Next, on mysql server install MySQL Server software:
sudo apt install mysql-server -y -
On mysql client install MySQL Client software:
sudo apt install mysql-client -y -
Edit Inbound rule on mysql server to allow access to mysql client traffic. MySQL server uses TCP port 3306 by default. Specify inbound traffic from the IP of mysql cient for extra security.
-
For mysql client to gain remote access to mysql server we need to create and database and a user on mysql server. To start with run the mysql security script:
sudo mysql_secure_installationFollow the prompts and answer appropraitely to finish the process. -
Run mysql command:
sudo mysqlThis would take you to the mysql prompt (You may be required to input password if you opten for the validate password during the security script installation) -
Next, create the remote user with this following command:
CREATE USER 'remote_user'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; -
Create database with:
CREATE DATABASE test_db; -
Then grant privieges to remote_user:
GRANT ALL ON test_db.* TO 'remote_user'@'%' WITH GRANT OPTION; -
. Finally, flush privileges and exit mysql :
FLUSH PRIVILEGES; -
Having created the user and database, configure MySQL server to allow connections from remote hosts. Use the following command:
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf -
In the text editor, replace the old Bind-address from ‘127.0.0.1’ to ‘0.0.0.0’ then save and exit.
-
Next, we restart mysql with:
sudo systemctl restart mysql -
From mysql client connect remotely to mysql server Database Engine without using SSH. Using the mysql utility to perform this action type:
sudo mysql -u remote_user -h 172.31.3.70 -pand enterpasswordfor the user password. -
This gives us access into the mysql server database engine.
-
Finally type:
Show databases;to show the test_db database that was created.