Creating a MariaDB user account for your WordPress application
In this lesson you will use the MariaDB shell to create a new database and a dedicated user account for your WordPress site with proper privileges.
The MariaDB shell
We already did a couple of things in the MariaDB shell in earlier lessons.
This is the quickest and most efficient way to access your MariaDB or MySQL
database. You can run the shell as the MariaDB root
user, using:
sudo mariadb
But you can also run this shell as any other user, by providing the username and password:
mariadb -u username -p
You should only use the root
account for administrative tasks, such as server
configuration and diagnostics, user account and database management. WordPress
and other applications requiring a MariaDB database should use a different
non-privileged account.
There are two keyboard shortcuts you need to know when working with the shell:
Ctrl+C
to interrupt a query or results output (very useful to kill a slow
query that you accidentally run), and Ctrl+D
to exit the shell (typing exit
usually works too).
Create database and user
Let's use the MariaDB shell and create a new database for our future WordPress site:
sudo mariadb
> CREATE DATABASE `uncached`;
> CREATE USER 'uncached'@'localhost' IDENTIFIED BY 'secure-password';
> GRANT ALL PRIVILEGES ON `uncached`.* TO 'uncached'@'localhost';
This will create a new database named uncached
, a new user named uncached
,
which can connect to the database locally using the specified password, and
grant that user all privileges on any table in this new database.
In MariaDB and MySQL, backticks are used for identifiers, such as database, table, and column names. You don't always need to use them, but it's a good habit. Single or double quotes are used for string literals.
Make sure you use a strong password for your database user, and use different user accounts for different sites on your server. This will prevent a compromised site from easily accessing another site's database. It will also come in handy if you allow external database access in the future, or run database software such as phpMyAdmin.
This article is for premium members only. One-time payment of $96 unlocks lifetime access to all existing and future content on wpshell.com, and many other perks.