How to access mysql database hosted on remote server using phpMyAdmin

First, login over ssh to remote MySQL database server:

Once connected you need to edit the MySQL server configuration file my.cnf using a text editor such as vi.

Edit /etc/my.cnf, run:
# vi /etc/my.cnf

Make sure line skip-networking is commented (or remove line) and add following line

bind-address=YOUR-SERVER-IP

Step# 4 Save and Close the file

If you are using Debian / Ubuntu Linux, type the following command to restart the mysql server:
 # /etc/init.d/mysql restart
 If you are using RHEL / CentOS / Fedora / Scientific Linux, type the following command to restart the mysql server:
 # /etc/init.d/mysqld restart

Step # 5 Grant access to remote IP address

Connect to mysql server:
$ mysql -u root -p mysql

Grant access to a new database

If you want to add a new database called foo for user bar and remote IP 202.54.10.20 then you need to type the following commands at mysql> prompt:mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON * TO root@103.11.155.6' IDENTIFIED BY 'PASSWORD';

How Do I Grant Access To An Existing Database?

Let us assume that you are always making connection from remote IP called 202.54.10.20 for database called webdb for user webadmin, To grant access to this IP address type the following command At mysql> prompt for existing database, enter:
mysql> update db set Host='202.54.10.20' where Db='webdb';
mysql> update user set Host='202.54.10.20' where user='webadmin';

Step # 6: Logout of MySQL

Type exit command to logout mysql:mysql> exit

Step # 7: Open port 3306

You need to open TCP port 3306 using iptables or BSD pf firewall.

A sample iptables rule to open Linux iptables firewall

/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

OR only allow remote connection from your web server located at 10.5.1.3:

/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp --destination-port 3306 -j ACCEPT
---------------------------------------------------------------------------------------------------------

Now the most important and final changes

/*$i++;
* Authentication type */
/*$cfg['Servers'][$i]['auth_type'] = 'cookie';*/
/* Server parameters */
/*$cfg['Servers'][$i]['host'] = '103.11.155.7';
* $cfg['Servers'][$i]['port'] = '3306';
* $cfg['Servers'][$i]['connect_type'] = 'tcp';
* $cfg['Servers'][$i]['compress'] = false; */
/* Select mysqli if your server has it */
//$cfg['Servers'][$i]['extension'] = 'mysql';
//$cfg['Servers'][$i]['auth_type']     = 'config';
/* User for advanced features */
// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';
/* Advanced phpMyAdmin features */
/*$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
* $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
*$cfg['Servers'][$i]['relation'] = 'pma_relation';
*$cfg['Servers'][$i]['table_info'] = 'pma_table_info';
* $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
* $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
* $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
* $cfg['Servers'][$i]['history'] = 'pma_history';
* $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';*/

$i++;
$cfg['Servers'][$i]['host']          = '103.11.155.7';
$cfg['Servers'][$i]['port']          = '3306';
$cfg['Servers'][$i]['socket']        = '';
$cfg['Servers'][$i]['connect_type']  = 'tcp';
$cfg['Servers'][$i]['extension']     = 'mysql';
$cfg['Servers'][$i]['compress']      = FALSE;
$cfg['Servers'][$i]['auth_type']     = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'GXW21h21';
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *