How do you create a MySQL-database for your WordPress website?

by | 13 May 2021 | WordPress, Website Maintenance

Have you created your own WordPress website? In this article, I’m going to explain how to create and load a MySQL-database and enable the database to be cleaned up automatically. You will get answers to the following questions:

  1. What is a database?
  2. How do you create a database?
  3. How do you load this database?
  4. How do you enable the database to be cleaned up automatically?
  5. How do you deal with a critical error?

Are you creating your first WordPress website? And have you run into difficulties? Well, I can relate. It always takes a while before you get used to doing something for the first time. That’s why some help from an expert is always welcome. In the 5 editions of this blog series, called ‘Need extra help with your first WordPress website?’, I will give information and pointers to help you on your way in the manual WordPress installation procedure. In this blog series we’ll take an in-depth look at episode 1 of my previous blog series ‘Create your own WordPress website in 7 steps’.

Discover the previous blog series here to create your own WordPress website.

How do you create a MySQL-database?

Once you’ve downloaded WordPress from WordPress.org and are about to install this manually, a ZIP file with a configuration file will be downloaded to your computer. Later on in this episode I will explain how to create a wp-config.php file with this so-called ‘wp-config-sample.php’ and load this with data to start the installation procedure. During the WordPress installation, the wp-config.php sends this data to a database. This database (full name: MySQL database) is a digital data bank where WordPress stores all of your website’s content and settings. The theme settings are also stored here. The database is the basis for your website.

Now you know what the database is for, it’s time for you to create one. It’s best to do this in your web host’s management panel, for example DirectAdmin or cPanel. I myself use DirectAdmin and the following instructions are based on this. However, the steps you take in cPanel are very similar. Once you’ve logged in to DirectAdmin, first click your domain name and then ‘MySQL Management’. Here you can create and manage a database. You can create the database by clicking ‘Create new Database’. In the dialog box that appears you will see the ‘database name’ and the ‘username’. You can still edit the username. Fill in a password, click ‘Create’ and your database is ready.

How do you load the MySQL-database?

In the next step, make a copy of the configuration file and name this copy: ‘wp-config.php’. So, that’s without the word ‘sample’. The original file will remain in the installation files in the ZIP file. After you’ve done this, you can load this file with data from the database. Do this as follows. Open the configuration file with Notepad (Microsoft) or TextEdit (Mac). Then go to the database that you made just now and copy the data items one by one to the configuration file.

You can see which data has to be loaded by the word ‘here’ preceded by a specific word, for example: ‘database_name_here’, ‘username_here’. In some sections there will be a couple of sentences that explain what information can be loaded or edited. Paste the data in the right spot in the configuration file. The reason for copying and pasting this instead of typing it letter for letter, is to lower the risk of typos. I will explain the importance of this later on in this episode.

Need help? Don’t hesitate to contact me!

Automatic cleaning up of the database

The basic data that you need to load are the ‘MySQL settings’, the ‘Authentication Unique Keys and Salts’ and the URL (full domain name). I also advise you to do the following:

  • Edit the table name to prevent access by hackers
  • Add the WordPress and website URLs and alter ‘http’ into ‘https’
  • Add the Force SSL for the https connection
  • Load the code for revisions 

What is the revisions code for? Each time you edit a web page or a blog post (make a revision), not only the edited version will be stored but the original version as well. So, the more data you store, the fuller your database will become. You won’t notice this at first, but after a while it can become overloaded, causing the website to upload slowly and the data limit to be exceeded. in addition, an overload of data makes it easier for other people to access the database.

This can be solved very easily by setting the number of revisions to 3, setting the recycle bin storage period to 7 days and having excess media files removed from the media gallery immediately and permanently. And this is done by adding extra codes to the configuration file. This ensures automatic cleaning up of the database. To make it easy for you, I’ve provided you with the code below. Now you only have to copy and paste this in the configuration file above the sentence: ‘/* That’s all, stop editing! Happy publishing. */’.

 /* Specify maximum number of Revisions. */
 define( 'WP_POST_REVISIONS', '3' );

 /* Post & Pages Trash interval. */
 define('EMPTY_TRASH_DAYS', 7); /*Interval is 7 days*/

 /* Trash media items */
define( 'MEDIA_TRASH', false ); /*Set true if you want a recycle bin*

How do you deal with a critical error?

Once the configuration file is complete, you’ll be ready for the final step in the installation procedure: installing WordPress on your domain. This is done via your web host’s FTP client. During the installation, the database is loaded with data from the configuration file, which will then be connected to it. Eventually, when you’ve finished your website and put it online, anything that you add, edit or remove in the backend will become visible right away.

That’s if the installation procedure goes according to plan. Because, if you’re out of luck, you won’t see an installation screen during the installation, but a white screen instead. This means a critical error has been made. A critical error is made when the configuration file is unable to connect with the database. This usually happens when the data that has been loaded is incorrect. For example, because the username has been misspelled. You can solve this by checking whether all of the data in the configuration file has been loaded properly. Even the slightest error can cause problems.

Here is a recap

Now you know how to create a MySQL-database, in order to install WordPress manually. Here is a recap of what you need to do:

  1. Create a database in ‘DirectAdmin’ or cPanel.
  2. Copy the configuration file and rename this new file ‘wp-config.php’.
  3. Copy and paste the necessary data as indicated in the configuration file.
  4. Load the code for revisions.
  5. Install WordPress on your domain via the FTP client.
  6. Check which data has been loaded incorrectly if there is a critical error.

Next time...

In the next episode, I’m going to show you around the WordPress dashboard and explain what you can use it for and what you can edit here. Questions that will be answered are: What can I do with the various dashboard features? How do I create a menu? And how do I edit this menu? I’m really curious about how this blog helped you. So, please feel free to share your experiences below and to share this story with other people. Are you having difficulty creating your website? Or are you looking for a web designer who creates solutions that help you along? Please contact me. I’d love to discuss the possibilities with you. Or have a look around on the website and webshop pages.

0 Comments