WordPress blogging platform is a PHP based web application and uses a MySQL database as a backend database. In this article we will explain in easy to follow step by step format how to manually create a MySQL database for your WordPress blog or website. Two options are explained below, either by connecting to MySQL using a web based graphical user interface such as phpMyAdmin, or by using the MySQL command line.
Once you have created the new WordPress MySQL database and have a user and password to access it, make sure you read the last section of this article “Recommended WordPress Database user privileges“ to make sure the most secure privileges are assigned to such user.
Creating a MySQL database using phpMyAdmin
There are several ways which you can use to connect to a MySQL database server to create a database, one of them is by using a web based graphical user interface such as phpMyAdmin.
- Once logged in to the phpMyAdmin interface, click on the Database Tab, specify a database name in the Create new database input file and click on Create button.
WP White Security.com Security Tip: Avoid using predictable database names, such as blogdatabase or blogdb. In case a malicious user is trying to guess such a name, it makes it a little bit more difficult to guess and potentially break the security of your WordPress.
- Create a new username and password to be used by WordPress PHP scripts to access the newly created MySQL database. To do so navigate to the Privileges tab and click on Add a new user.
- In the Add new user page shown above, enter a username, host and password, and ignore all other entries. If WordPress is going to be installed on the same server where MySQL is (typical scenario) the host should be set to Localhost. This means that this user is always going to connect from the same computer and requests using such credentials from a remote server will be denied.
WP White Security.com Security Tip: Avoid using predictable usernames, such as bloguser or blogusr. Also, a strong password should consist of at least 8 characters and should include alphabetical letters, numeric characters and as well special characters. Ideally the password should not be a dictionary word. An example of a good password is: !Pi4aX_7z?
- Once the new user is created, from the same Privileges tab click on Edit Privileges for the newly created user.
- In the Edit Privileges page, scroll down to the Database-specific privileges section so you can assign the user privileges only to the new WordPress MySQL database. Select the database from the drop down menu as shown in the screen shot below.
- Once the database is selected, you are redirected to a page from where you can specify the database specific privileges, as shown below.
- As shown in the above screenshot, for installing WordPress it is safe to assign all privileges apart from the Administration privileges to a user.
Creating MySQL database for WordPress via Command Line
- Connect to the MySQL engine using the command mysql –u root –p. Once you specify the password you will be connected to the MySQL database and prompted with mysql> prompt.
- To create a database use the CREATE DATABASE command. E.g. if you would like to create the database T3stdb123 enter the following:
CREATE DATABASE T3stdb123;
- Once the database is created, use the command GRANT ALL PRIVILEGES to create a new user with ALL privileges. If the database name is t3stdb123, the new user is newdbuser and the user’s passwords is !Pi4aX_7z? then the command should be;
GRANT ALL PRIVILEGES ON t3stdb123.* TO "newdbuser"@"localhost" IDENTIFIED BY "!Pi4aX_7z?";
- Once the new user has been created and privileges has been assigned to it, run the command FLUSH PRIVILEGES; to flush the old privileges and start using the new assigned ones.
Recommended WordPress Database Permissions
For typical WordPress operation, the MySQL database user only needs SELECT, INSERT and UPDATE data privileges. It is recommended to use the minimum possible privileges when running WordPress. Any other privileges, such as ALTER, CREATE and DROP are sometimes needed during an upgrade or when installing some plugins which need access to change the database structure. In such case you will be advised to do such changes by the plugin developer.Whenever you assign structure related privileges do it ONLY for temporary period. You can read more about WordPress database privileges from the article Why minimum MySQL user WordPress database privileges help.