Every WordPress installation has a database in the backend. That’s one of WordPress’ requirements.
Now, there are many different database servers you can use with WordPress. From MySQL to MariaDB to Percona and MongoDB, all of these different database servers should work just fine with WordPress.
Because you can’t use all of them at the same time, you must select one to use with WordPress. For this post, we’re going to be using MySQL databases to connect WordPress.
This brief tutorial is going to show you how to create WordPress MySQL database and user, and how to grant the user rights to manage the WordPress database.
To get started with managing WordPress’ MySQL databases, follow the steps below:
Step 1: Install MySQL
If you haven’t installed MySQL yet, the commands below show you how to install it on Ubuntu.
sudo apt-get update
sudo apt-get install mysql-server mysql-client
During the installation, you’ll be prompted to create and confirm a new root password for MySQL. Please type and confirm a password to continue.
This is the same password you’ll use to sign onto MySQL server.
Step 2: Sign on and Create a WordPress Database and User
After the database server has been installed, run the commands below to sign onto the database.
sudo mysql- u root -p
You’ll be prompted for a password.. type the password you created earlier during the installation.
After signing on to MySQL database server, run the commands below to create a new WordPress database called wpdb.
CREATE DATABASE wpdb;
This will create a new WordPress database called wpdb.
After creating the WordPress database, you’ll also need to create a database user. This account will be used by WordPress to interact with the database. To create the database user named wpuser, run the commands below.
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'type_user_password_here';
The above commands create a new database user called wpuser.
Now you should have both the database and user created. The user does have not any rights to the database. In order for the database user to interact on behalf of WordPress, including making changes to the data in the database, the user will need the rights to do these things.
To give the user full rights to mange the database, run the commands below
GRANT ALL ON wpdb.* TO 'wpuser'@'localhost;
The commands above grant wpuser all rights to manage all the tables in the wpdb database.
To grant the user right to a single table, run the commands below
GRANT <permission> ON wpdb.<table> TO 'wpuser'@'localhost;
Replace <permission> with one of these permission levels.
- SELECT – gives the user permission to use the select command to fetch data from tables
- INSERT – gives the user permission to add new rows into tables
- UPDATE – gives the user permission to modify the existing rows in tables
- DELETE – gives the user permission to delete existing rows from tables
- CREATE – gives the user permission to create new tables or databases
- DROP – gives the user permission to remove existing tables or databases
- ALL PRIVILEGES – gives the user permission to have unrestricted access on a database or the whole system(by using an asterisk in the database position)
This is how WordPress databases and users are created on MySQL.
This post shows students and new users how to create databases, users and grant users access to databases. After creating the database and the user, you can then configure WordPress to use it.
You may also like the post below:
Sharing Windows 10 Shares with Ubuntu 17.04 via Samba