Many websites keep their content in a database: posts, products, customers and settings. Systems such as WordPress cannot run without one. Creating a database takes three small steps: the database, a user, and the link between them.
Create the database
- Sign in to cPanel and open MySQL Databases.
- Under Create New Database, type a short name such as
shopand press Create Database.
cPanel puts your account name in front, so the full name becomes something like account_shop. Use the full name everywhere.
Create a user
A website does not sign in to the database with your control panel password. It uses its own database user.
- On the same page, go to MySQL Users › Add New User.
- Type a username and press Password Generator for a strong password.
- Copy the password to a safe place before you close the window, then press Create User.
Give the user access
- Under Add User To Database, choose the user and the database and press Add.
- On the next page tick All Privileges and press Make Changes.
The website now has what it needs: database name, username, password, and the server name, which is localhost in nearly all cases.
Use the wizard instead
MySQL Database Wizard in cPanel asks the same three things one after another. Use it if you prefer to be guided.
Import existing data
If you move a website from another host, you have a file ending in .sql or .sql.gz.
- Open phpMyAdmin in cPanel.
- Click the name of your new database in the left column.
- Open the Import tab, choose the file and press Go (or Import).
A green message confirms the import. If the file is larger than the limit shown on the page, compress it as .sql.gz, or open a ticket and we will import it for you.
Connect the website
Enter the four values in the configuration of your website:
- WordPress: the file
wp-config.phphas the linesDB_NAME,DB_USER,DB_PASSWORDandDB_HOST. - Other systems: look for a file named
.env,config.phporconfiguration.php, or the settings page of the installer.
"Error establishing a database connection"
This message means one of the four values is wrong, or the user was not added to the database.
- Compare the database name and the username with cPanel, including the part in front of the underscore.
- Set a new password for the user in cPanel under Current Users › Change Password and enter the same one in the configuration file.
- Check under Current Databases that the user is listed beside the database.
- Keep the host as
localhostunless we told you otherwise.
Look inside the database
phpMyAdmin shows the tables of a database and lets you search and change single values. This is useful for small repairs, for example to change the address of a WordPress site in the options table after a move. Make an export first: one wrong click in a database cannot be undone.
Export a backup
- Open phpMyAdmin and click the database.
- Open the Export tab, keep the quick method and the SQL format, and press Go.
The file that downloads is a complete copy. Do this before every update of your website.
Connect from your own computer
By default a database accepts connections only from the website on the same server, which is the safest setting. If you need to connect from a program on your computer, add your internet address under Remote MySQL in cPanel, and remove it again when you are done.
How many databases can I have?
The number depends on your plan and is shown on the right side of cPanel under Statistics. One database per website is the usual and tidy arrangement. Sharing one database between two websites works only when their table names start differently, and it makes backups harder to handle.