Whitelisting an IP in Linux Iptables for remote MySQL.

Step 1

Open port 3306 in Linux Iptables for remote MySQL by running this in ssh.

root@server [~]# iptables -A INPUT -i eth0 -p tcp -m tcp –dport 3306 -j ACCEPT

Step 2

In order to whitelist remote servers or your IP you would need to run this mysql command.

root@server [~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 85140329
Server version: 5.5.48-37.8 Percona Server (GPL), Release 37.8, Revision c8ae1b6

Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> GRANT ALL PRIVILEGES ON dbname.* TO username@’IP’ IDENTIFIED BY ‘password’;

Please make sure you have “skip-networking” commented in your /etc/my.cnf