Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Set up remote access to MySQL database on Ubuntu

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 399
    Comment on it

    Without database any application is almost redundant. So this post might help you to setup access to MySQL database on Ubuntu.

    Firstly you need to open up the MySQL server config file present at

    /etc/mysql/my.conf

    and search for the line

    bind-address = 127.0.0.1
    

    Note - Always take backup of the file you are changing and use nano editor by typing the following command

    sudo nano my.conf
    

    It will ask for password. Enter the password and the file will open up.

    The line bind-address = 127.0.0.1 actually binds MySQL connections to localhost only.

    Comment out this line by adding # at the front of this line

    After commenting out the line it should look like this

    #bind-address = 127.0.0.1
    

    Now save this file and restart MySQL by

    mysql restart 
    

    You are all good to go but this only enables MySQL access on local network

    If you want to access MySQL from a remote ip address then the following procedure will help you

    Before granting user access, you need to login to MySQL from SSH:

    $ mysql -u root -p 
    

    Enter the password when prompted. It is the same password which was specified during MySQL installation.

    Grant user access

    Assumptions:

      You have a database called TEST
      You would like to allow remote access to this database from a IP address 14.141.58.163
      The MySQL username is MY_USERNAME and the password is MY_PASSWORD

    Change the IP address, database name, username and password according to yours.

    To grant remote access, type the following command from MySQL prompt:

    mysql> CREATE USER 'MY_USERNAME'@'localhost' IDENTIFIED BY 'MY_PASSWORD';
    
    mysql> GRANT ALL PRIVILEGES ON TEST.* TO 'MY_USERNAME'@'14.141.58.163' IDENTIFIED BY 'MY_PASSWORD'; 
    

    On successful execution you see a message saying something like Query OK, 0 rows affected (0.00 sec)

    Restart MySQL by firstly quitting MySQL:

    mysql> quit 
    

    Then type the following command at the SSH prompt:

    mysql restart 
    

    Now you can access MySQL remotely through the ip you granted access to.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: