How to connect to the MySQL database Print

  • 54

 

 

MySQL is a powerful relational database management system (RDBMS) widely used for managing and organizing data. This guide outlines how to connect to a MySQL database using cPanel and DirectAdmin, along with instructions for remote connections.


Connecting via cPanel

Step 1: Log in to cPanel

  • Navigate to your cPanel login page. For example:
    example.com/cpanel
  • Enter your username and password, then click Log in.

Step 2: Access the 'MySQL Databases' Section

  • Scroll to the Databases section and click on the MySQL Databases icon.

Step 3: Create a New MySQL Database (if needed)

  • Enter a name for your database in the provided field.
  • Click the Create Database button.

Step 4: Create a New MySQL User (if needed)

  • In the MySQL Users section, enter a username, password, and confirm the password.
  • Click Create User.

Step 5: Add the User to the Database

  • Select the user and the database from the drop-down menus.
  • Click the Add button.
  • On the next screen, select the required privileges for the user and click Make Changes.

Step 6: Obtain Database Connection Details

  • Database name: cpanelusername_databasename
  • Database username: cpanelusername_databaseusername
  • Password: Your MySQL user password.
  • Hostname: Typically localhost.

These details are displayed in the MySQL Databases section.


Connecting via DirectAdmin

Step 1: Log in to DirectAdmin

  • Navigate to your DirectAdmin login page and enter your username and password.

Step 2: Access the 'MySQL Management' Section

  • Click on the MySQL Management icon under the Extra Features section.

Step 3: Create a New MySQL Database (if needed)

  • Enter a name for your database and click Create.

Step 4: Create a New MySQL User (if needed)

  • Click the Add User button.
  • Enter a username, password, and confirm the password.
  • Click Save.

Step 5: Add the User to the Database

  • Click on Assign User to Database.
  • Select the user and database from the drop-down menus.
  • Click Save.

Step 6: Obtain Database Connection Details

  • Database name: directadminusername_databasename
  • Database username: directadminusername_databaseusername
  • Password: Your MySQL user password.
  • Hostname: Typically localhost.

These details can be found in the MySQL Management section.


Remote Connection to MySQL

Configuration Settings for Remote Access

  • Host: Server IP address.
  • Database name: cpanelusername_databasename.
  • Database username: cpanelusername_databaseuser.
  • Password: Your MySQL user password.
  • Port: 3306.

Enabling Remote MySQL Access in cPanel

  1. Log in to cPanel.
  2. Click on the Remote MySQL icon under the Databases section.
  3. Enter the IP address of the remote system in the Add Access Host field.
  4. Click Add Host.

Handling Dynamic IP Addresses

  • If your IP changes frequently, you have options:
    1. Update your IP in Remote MySQL each time it changes.
    2. Use % in the Add Access Host field to allow connections from any IP.
    3. Restrict access to a range by using a partial IP, such as 93.138.%.

Configuration Example

For Local Connections:

  • Host: localhost
  • Database name: cpanelusername_databasename
  • Username: cpanelusername_databaseusername
  • Password: Your MySQL password.

For Remote Connections:

  • Host: Server IP address.
  • Port: 3306.
  • Database name: cpanelusername_databasename
  • Username: cpanelusername_databaseusername
  • Password: Your MySQL password.

Notes

  • When migrating databases, update the database name and username in your script.
  • Always back up your database before making significant changes.

By following this guide, you can efficiently connect to and manage your MySQL database locally or remotely using cPanel or DirectAdmin.


Was this answer helpful?

« Back