Core points
This article is part of a series of articles created in collaboration with SiteGround. Thank you for supporting the partners who made SitePoint possible.
WordPress's success is largely due to its quick and easy five-minute installer. However, the MySQL database still confuses many people.
This tutorial shows how to create a database using cPanel, a popular platform management utility provided by many web hosts. We will also discuss how to use this database during WordPress installation. Any web application that requires MySQL can use these technologies.
Let's start with the basics and terms...
The database is a collection of organized data. That's it. WordPress stores all its pages, posts, categories, and user data in a database.
MySQL is a database management system (DBMS). It is a software that allows you to create, update, read and delete data from a database. A single MySQL installation can manage any number of self-contained databases. You can create one for WordPress, one for Magento, one for Drupal or any other application you need.
There are many alternatives, but there are several reasons why MySQL is popular:
Applications such as WordPress access their data through a database connection. For MySQL, a connection can be established only if the PHP code of WordPress knows the following information:
The database "user" account must be defined for WordPress use. It can have very powerful passwords and set appropriate database permissions.
MySQL and other SQL databases store data in relational tables.
For example, you might have a set of posts. Each post will have unique data such as title and body text. It will also have data used in other posts, such as category and author details. To avoid duplicating the same data, we create separate tables:
SQL database implements security measures to ensure data integrity. You should not be able to cite non-existent author IDs or delete the categories used by one or more articles.
These table definitions and rules constitute the database pattern. Execute a set of SQL commands to create this pattern during WordPress installation. Only in this way can the table be ready to store data.
Use cPanel's web host to provide a web address (such as https://site.com/cpanel) as well as a username and password for access. Please keep these details properly. Don't confuse them with database or WordPress user credentials!
If you are looking for a host that supports cPanel, try SiteGround, which is the host we chose. All plans support cPanel, and they have redesigned the dashboard to organize everything in a more friendly way.
Your view may look slightly different, but please find the "Database" section or enter "MySQL" in the search box.
Click on the MySQL Database Wizard and follow the steps:
Your database needs a name:
name may have a prefix applied, such as mysite_. Enter an appropriate name, such as blog or wordpress, and click Next.
You must now define the MySQL user account that WordPress uses to access the database:
Please note that the username may also have the same prefix (mysite_). In this screenshot, our user ID is mysite_blogDBuser.
cPanel will ensure that you enter a strong password. Passwords can be complicated; you will only use them once during WordPress installation. I recommend a random password generator:
Before clicking Create User, make sure to copy the user ID and password to a text file or other secure location.
During the WordPress installation process, the users created above need to have full access to the database. It runs scripts to create tables and populates them with initial data.
Select "All Permissions" and click "Next":
cPanel will confirm the creation of the MySQL database and user.
You can use the MySQL database panel instead of the wizard. It still allows you to create a database and a user, but you then add that user to the database.
It also provides tools to update, repair and delete databases and users.
Your cPanel may provide WordPress and other application installers. Since the script creates a database for you, the above steps may not be required.
If you need to or prefer to manually install it, download WordPress and unzip the file. You may be able to do this on the server via SSH, but FTP/SFTP is also supported.
Open your browser and navigate to the domain/path where you copied WordPress (i.e. http://mysite.com/). This will start the installation:
You must enter:
Table prefix will add a short string before all table names. When changing it:
Click Submit and WordPress will verify your credentials and continue to install.
WordPress prompts for the WordPress administrator's ID, password and email address. This is the person who manages WordPress. It's different from MySQL database and cPanel credentials!
Click "Install WordPress" and the dashboard will appear in seconds.
We granted full permissions to the database user to install WordPress. You can lower these permissions after installation for increased security.
The following permissions should be sufficient:
Some plugins may require additional permissions, so if you have problems, enable All Permissions.
Protecting WordPress MySQL database on cPanel is essential to protect your website from potential threats. First, use a powerful and unique password for your database. cPanel has a built-in password generator that you can use. Regularly update your WordPress and plugins to the latest version, as they usually contain security patches. Limit the number of failed login attempts to prevent brute force attacks. You can also install security plugins like Wordfence or Sucuri for extra protection. Finally, always back up the latest version of your website. cPanel's backup wizard tool can help you do this.
If you forget your MySQL database password, you can reset it via cPanel. Go to the MySQL database, locate the database user whose password you want to change, and click Change Password. Enter your new password or use the password generator to create a powerful password. Remember to update the wp-config.php file in your WordPress installation with a new password.
Optimizing WordPress MySQL database can improve website performance. You can use cPanel's Optimized Database feature, which is located in the MySQL Database section. Also, consider using WordPress plugins like WP-Optimize or WP-Sweep. These plugins can clean up the database by deleting unnecessary data such as deleted posts, revisions, and spam.
Yes, you can create multiple MySQL databases for a WordPress website, but this is usually not required. WordPress can be run using a database. If you are running a multi-site network or creating complex custom applications, you may need multiple databases.
To connect your WordPress website to a MySQL database, you need to edit the wp-config.php file. This file contains your database name, username, and password. You can access this file through cPanel's file manager. Be sure to back up your website before making any changes to the file.
phpMyAdmin is a free software tool for handling MySQL management over the network. It provides a convenient visual interface to manage your database. You can use phpMyAdmin to create, modify, and delete databases, tables, fields, and rows. You can also use it to execute SQL statements as well as manage users and permissions.
You can use cPanel's backup wizard tool to back up your WordPress MySQL database. This tool allows you to download compressed copies of the entire website or part of its content to your local computer. It is recommended to back up your website regularly to prevent data loss.
To restore a WordPress MySQL database from a backup, you can use cPanel's backup wizard tool. Select Recover, and then select MySQL Database. Upload your backup file and the tool will restore your database. Remember to back up your website before performing any recovery actions.
If your WordPress website slows down after creating a MySQL database, it can be caused by a variety of reasons. Your database may need to be optimized, or your website may have too many plugins installed. Consider using a cache plugin to speed up your website. If the problem persists, please consult your hosting provider.
Yes, you can migrate your WordPress MySQL database to another server. You need to export the database from the current server and then import it to the new server. You can do this using phpMyAdmin in cPanel. Remember to update your wp-config.php file with the new database information.
The above is the detailed content of How to Create WordPress MySQL Databases on cPanel. For more information, please follow other related articles on the PHP Chinese website!