Wednesday, June 16, 2010

How to connect to a remote mySQL database using PHP

  1. You need to access the remote server or get in touch with the remote server's tech support.
  2. Then
    use the_database_name;

    GRANT ALL PRIVILEGES ON
    the_database_name.*
    TO
    'the_user_in_php_code'@'%'
    IDENTIFIED BY
    'password_of_the_user_in_php_code';

    FLUSH PRIVILEGES; 
  3. If you are using phpmyadmin in your remote server, simply login and add a privileged for your host.
    - Select the database from the list
    - Click Privileges
    - Click "Open new phpMyAdmin window" which can be found in the bottom right corner
    - Click "Add a new User" which is located below the list.
    - Fill in the form.

    -- User name: desired_user_name
    -- Host: your_IP_given_by_your_internet_service_provider
    -- Password: desired_password
    -- Re-type: desired_password

    - Click "Go"
    - In the "Database-specific privileges" section select the database for the "Add privileges on the following database:" field.
    - Select "Check All" and Click "Go"
    - Done.
Note: edit /etc/mysql/my.cnf
bind-address            = local ip (example: 192.168.2.80)
restart mysql or restart computer

No comments:

Post a Comment