Thursday, 23 June 2016

Connect to your MySQL database remotely

Getting your IP address

You will need to know what the IP address you are connecting from. To find this you can go to one of the following sites:

Granting access

Granting access to a user from a remote host is fairly simple and can be accomplished from just a few steps. First you will need to login to your MySQL server as the root user. You can do this by typing the following command:
# mysql -u root -p
This will prompt you for your MySQL root password.
Once you are logged into MySQL you need to issue the GRANT command that will enable access for your remote user. In this example we will be creating a brand new user (fooUser) that will have full access to thefooDatabase database.
Keep in mind that this statement is not complete and will need some items changed. Please change 1.2.3.4to the IP address that we obtained above. You will also need to change my_password with the password that you would like to use for fooUser.
mysql> GRANT ALL ON fooDatabase.* TO fooUser@'1.2.3.4' IDENTIFIED BY 'my_password';
This statement will grant ALL permissions to the newly created user fooUser with a password of ‘my_password’ when they connect from the IP address 1.2.3.4.

Testing remotely

Now you can test your connection remotely. You can access your MySQL server from another Linux server:
# mysql -u fooUser -p -h 44.55.66.77
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> _
Note that the IP of our MySQL server is 44.55.66.77 in this example.
==============================================================================

Steps
YOUR SIDE
1) my ip:192.168.1.186    (databases present in this)       remote ip: 192.168.1.211
2) login into your mysql with root
mysql> GRANT ALL ON fooDatabase.* TO fooUser@'1.2.3.4' IDENTIFIED BY 'my_password';
3)mysql>GRANT ALL ON  DatabaseName.* To rahul@'192.168.1.211' IDENTIFIED BY '1234'
REMote SIde
4) Testing from remote computer(192.168.1.211)
 After runny mysql in remote server
mysql> mysql  - u rahul  -p -h 192.168.1.186

5) now you will be connected to mysql database on (192.168.1.186)







No comments:

Post a Comment