1 |
Sample Setup |
1 2 3 4 5 6 7 8 9 10 11 12 |
+----------- server1 192.168.1.6 | +------------ tomcat1 192.168.1.7 | +------------------+ | | MySQL Server | --------+------------ apache2 192.168.1.8 | 192.168.1.5:3306 | --------+ +------------------+ | LAN 192.168.1.0/24 +------------- pc1 192.168.1.51 | | +-------------- pc25 192.168.1.76 |
You need to allow access to 192.168.1.5 from apache server located at 192.168.1.8.
Step #1: Configure MySQL Server For Remote Access
1 2 3 4 5 |
$ ssh root@192.168.1.5 [/bash] Edit /etc/my.cnf, enter: # vi /etc/my.cnf |
Modify or append as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# make sure the following line is deleted or commented out # skip-networking bind-address = 192.168.1.5 # ------------------ # Save and close the file. Restart the mysql server, enter: # service mysqld restart Verify that the TCP port 3306 is open, enter: Make Sure TCP Port # 3306 is Opened For Business # netstat -tulpn | grep :3306 |
Step #2: Linux Firewall Configuration For TCP Port # 3306
# >>>> You need to open TCP port # 3306 at the firewall level, enter:
1 2 3 4 5 6 7 8 9 10 11 |
# iptables -A INPUT -i eth0 -s 192.168.1.8 -p tcp --destination-port 3306 -j ACCEPT # service iptables save Step #3: Configure Database Remote Access # mysql -u root -p mysql mysql> update db set Host='192.168.1.8' where Db='salesdb'; mysql> update user set Host='192.1681.8' where user='foo'; mysql> \q # Login to 192.168.1.8 and type the following command to test mysql server remote access: $ mysql -u foo -h 192.168.1.5 -p salesdb |
Sample outputs:
1 2 3 4 5 6 7 |
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 27720995 Server version: 5.0.77 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> |