How to create a database in WordPress?

The WordPress content management system saves user settings, theme settings, post data, tags, categories, etc in a database. In other words, we can say that the DB is the backbone of the WP content management system. The shared hosting companies will automatically create a database when you use their 1-click WP installer tool. But, if you’re using an unmanaged hosting service, you may have to create a database for your WP site manually. Below, we’ve covered the steps you can follow to create a MySQL DB for your WordPress site.

SSH method

To create a WP DB using this method, log in to the server using the ssh user_name@ipaddress command and now login to the DBMS as a user who has permission to create or manage DB using this command mysql -u root -p. When you enter this command and press the enter key, you’ll be prompted to enter the password.

Once you’ve logged in, create a database using create database database_name command. When your DB has been created, create a user who can read data from the WP table or write to the various WP DB tables. Use this command to create the MySQL user:

CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';

A user won’t be able to read DB data nor modify the records unless you grant all permissions to the user. Thus, you should execute the following command immediately after creating the DB.

CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';

GRANT ALL ON db_name.* TO 'user_name'@'localhost';

Now, run the flush privileges MySQL command.

Note: In the above commands, replace user_name with the custom user name, db_name with the name of the database, and password with the user password of your choice.

Before signing out of the DBMS, note down the user name, the password of the user, and the database name. You’ll also have to update the WordPress configuration file (wp-config.php) with these details. Where is the wp-config file located? You can find the wp-config PHP file in the WP installation directory. If your hosting company lets you access the server via SSH, you can use this method to create the DB on the server.

PHPMyAdmin method

PHPMyAdmin is a great DBMS administration tool. It lets you work on a database using a graphical user interface. To create a DB using PHPMyAdmin, log in to PHPMyAdmin, and click the DB menu. Now, find the option “create database”, enter the name for your DB in the text field and click the “Create” button. Once your DB is ready, create a user for the DB. To do so, click the “users” menu and click on the “Add user” option. Fill out the form PHPMyAdmin shows with the username, password, etc, and save the user.

As you can see above, creating a WP database is easy, no matter what method you use.

pramod
Pramod

Pramod is the founder of wptls. He has been using WordPress for more than nine years. He builds web applications, and writes about his experiences with various WP products on this site.

Leave a Reply

Your email address will not be published. Required fields are marked *