How to connect to the MySQL database Print

  • 54

Introduction: MySQL is a widely-used open-source relational database management system (RDBMS) that enables you to store, organize, and manage data efficiently. To interact with a MySQL database, you need to establish a connection between your application or website and the database server. In this article, we'll guide you on how to connect to a MySQL database using cPanel and DirectAdmin control panels.

cPanel:

Step 1: Log in to cPanel Log in to your cPanel account using your username and password.

Step 2: Access the 'MySQL Databases' section Navigate to the 'Databases' section and click on the 'MySQL Databases' icon.

Step 3: Create a new MySQL database (if needed) If you haven't already created a MySQL database, you can do so by entering a name for your new database and clicking on the 'Create Database' button.

Step 4: Create a new MySQL user (if needed) To connect to your database, you'll need a MySQL user with the appropriate privileges. If you haven't already created a user, you can do so by entering a username, password, and password confirmation. Click on the 'Create User' button.

Step 5: Add the user to the database To grant the MySQL user access to your database, select the user and the database from the respective drop-down menus, then click on the 'Add' button. In the next screen, select the privileges you want to grant the user and click on the 'Make Changes' button.

Step 6: Obtain the database connection details To connect to your MySQL database, you'll need the database name, username, password, and hostname. The hostname is typically 'localhost' or the server's IP address. You can find this information in the 'MySQL Databases' section of cPanel.

DirectAdmin:

Step 1: Log in to DirectAdmin Log in to your DirectAdmin account using your username and password.

Step 2: Access the 'MySQL Management' section Navigate to the 'Extra Features' section and click on the 'MySQL Management' icon.

Step 3: Create a new MySQL database (if needed) If you haven't already created a MySQL database, you can do so by entering a name for your new database and clicking on the 'Create' button.

Step 4: Create a new MySQL user (if needed) To connect to your database, you'll need a MySQL user with the appropriate privileges. If you haven't already created a user, you can do so by clicking on the 'Add User' button. Enter a username, password, and password confirmation, then click on the 'Save' button.

Step 5: Add the user to the database To grant the MySQL user access to your database, click on the 'Assign User to Database' button. Select the user and the database from the respective drop-down menus, then click on the 'Save' button.

Step 6: Obtain the database connection details To connect to your MySQL database, you'll need the database name, username, password, and hostname. The hostname is typically 'localhost' or the server's IP address. You can find this information in the 'MySQL Management' section of DirectAdmin.

Connecting to a MySQL database in cPanel and DirectAdmin is a straightforward process. By creating a database, adding a user with the necessary privileges, and obtaining the database connection details, you'll be able to interact with your MySQL database efficiently. These details can be used in your website or application to establish a connection and perform various database operations.

Configuration Settings:
Host = localhost (really, put localhost)
Database name = (cpanelusername_databasename)
Database username = (cpanelusername_databaseusername)
Database password = (******)

Note: When you move databases to our servers, the database name and username may change. This change must be updated in your script code. (The database name and username is clearly displayed in cPanel, in the MySQL area.)


How to connect to the MySQL server remotely

Configuration Settings:
Host = (use the server IP address)
Database name = (cpanelusername_databasename)
Database username = (cpanelusername_databaseuser)
Database password = (******)
MySQL Connection Port = 3306
TCP or UDP, either is fine.

Before you can connect to MySQL from another computer, you must enable your computer as an Access Host. It may sound confusing, but cPanel makes this very simple.

  1. Login to cPanel and click the Remote MySQL icon, under Databases.
  2. Type in the connecting IP address, and click the Add Host button.
  3. All done, try connecting remotely.

Wait a minute, my IP constantly changes.
Okay, you have a dynamic IP address. Therefore, every time you go online, or every once in awhile, your IP changes. You have a few options here. The most secure, would be to update your IP in Remote MySQL every time your IP changes. However, you do have other options available. You could simply enter % (a percentage sign) in the Add Access Hosts text field. This will allow any IP to remotely connect to your databases. Another option: Lets say the first two parts of your IP never change. Then, you could enter 93.138.%.% , where the first two parts are your actual IP address numbers.

 


Je li Vam ovaj odgovor pomogao?

« Nazad