Answer ID: 1445


I'm having problems connecting to a MySQL database. How do I test MySQL connectivity?


To test your MySQL connectivity:

  1. Copy and paste the below text into a blank text file. 

    <?php

    $db = "Database name";                          #Database name

    $user = "Database username";                 #Database username

    $pass = "Database password";                 #Database password

    $host = "Database server";                       #Database server

    $conn = mysql_connect($host,$user,$pass) or die("could not connect to server " .mysql_error());

    mysql_select_db($db) or die("could not connect to database " .mysql_error());

    echo ("Database Connected");

    ?>

  2. Fill in the database name, database username, database password and database server fields. If you are unsure of what information to enter, please do the following:

    • Linux hosting:

      Please see the article, "Managing Users for Databases" to determine your user name and password, and to determine which database server to connect to.

  3. Once you have updated the file with the appropriate information, save it as SQLtest.php and upload it to your hosting account (see Web Hosting: Upload Files to Web Hosting Account). Then, run the script by navigating to the file in a web browser (e.g., "http://www.mydomain.com/SQLtest.php").

  4. If all the information was entered correctly, you should receive the message, "Database Connected." If you receive an error message, double-check the information that you entered into the script. If you still can't connect, please copy and paste the script into a support ticket.


NOTE: We do not allow remote connections to the database server. If you are encountering errors while attempting to use a desktop application to connect to the database, this is probably why.

NOTE: Specifying "localhost" for the database server will not work. Please use the appropriate server name, as specified above.