WordPress Install – Part 5

Return to: Part 4

MySQL – Installation Overview

PHP requires the php-mysql extension to communicate with your database – installing it is described in the previous section.

There are four additional steps required to install the necessary database for WordPress

  1. Install the package containing the database software that’s compatible with MySQL.
  2. Run the initial MySQL configuration script.
  3. Create user ID’s and passwords to the database system.
  4. Create the database for WordPress

Your distribution’s repository may dictate what database software is installed. For example, installing the mysql package may result in an alternate, but compatible, database installation – such as MariaDB. A compatible database such as MariaDB may have different wording in the prompts – but it will respond to your commands exactly the same as MySQL.

All the commands for installation and configuration can be done at the command line. My examples use this method – and for anyone new to these procedures, I recommend following my examples.

There are sophisticated server and database management tools that can also do the installation and configuration. If you’re not already proficient with using such tools, I don’t recommend them for your first database installation.

reference: https://wordpress.org/support/article/creating-database-for-wordpress/

There are also MySQL database “work bench” tools that allow doing MySQL tasks with a graphical user interface instead of the command line. Installing one can be helpful – because you don’t have to know MySQL command syntax. However the workbench tools are not a substitute for understanding MySQL fundamentals.

reference: https://en.wikipedia.org/wiki/Comparison_of_database_tools

reference: https://codingsight.com/10-best-mysql-gui-tools/

MySQL Security Considerations

MySQL has user id’s and passwords just like your operating system. It always has a user id called “root” that has unlimited access.

For safety and security reasons, it’s recommended that the MySQL root user be used only to create other MySQL user ID’s – that have fewer privileges.

I recommend creating two additional MySQL user id’s – one to be used by the WordPress application. This is similar to my examples of creating the wp-ops user id for your operating system – to avoid using the operating system’s root account.

The other to be used for remote access to the database – such as a workbench tool. With this second user id, you can deactivate remote access to your database by the root account – which protects it from malicious internet attack.

MySQL also requires selecting the complexity of required passwords. I use “medium” – but your needs may differ.

Install the MySQL Package

Unless you did the APT updates recently, you may wish to repeat them here. Then install MySQL as follows:

~$ sudo apt install mysql-server↵

It’s possible that your distribution’s repository doesn’t have MySQL – but some other database system that’s compatible with MySQL. If so – you might get an APT report like this:

wp-ops@seebylooking:~ $ sudo apt install mysql-server↵
[sudo] password for wp-ops: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package mysql-server is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  mariadb-server-10.0

E: Package 'mysql-server' has no installation candidate
wp-ops@seebylooking:~ $

In this instance, we’re advised to install MariaDB. Install it with the command:

~$ sudo apt install mariadb-server↵

The APT report from this installation would be similar to this:

If you’re using some other MySQL compatible database the installation should be similar using:
sudo APT install database-package-name

Run the MySQL Configuration Script

All MySQL compatible databases will have a similar installation script. But they should all have the same command name:

~$ sudo mysql_secure_installation↵

You will be prompted if a root password is to be set. I recommend yes. respond: “y”

You may be prompted for what level of password strength you wish. If you’re unsure, you might wish to choose the option number for “medium”.

If you’ve responded that you wish to set a root password, you’ll be prompted to enter it – and confirm it.

You’ll be asked if you wish to remove anonymous users. WordPress doesn’t require anonymous users – so I recommend you remove this. respond: “y”

When prompted if you wish to disallow root to login remotely. For security, I recommend you disallow remote root login. respond: “y”

This is a screen capture from running mysql_secure_installation:

You can test your MySQL installation:

~$ sudo mysql -u root -p↵

If necessary, you’ll be prompted for your sudo password, and then your MySQL root password.

wp-ops@seebylooking:~$ sudo mysql↵
[sudo] password for wp-ops:
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30200
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

MySQL Commands

It pays to take some time and practice with a few basic MySQL commands. Two things to know before you start:

  • MySQL commands end with a semicolon. “;” If you press enter with out a concluding semicolon you’ll get a new MySQL prompt until you do. Watch out for not matching quotes. If you get hung up, press control-C then enter.
  • To disconnect from MySQL type exit and press enter.

To verify your MySQL installation, you might simply connect to MySQL and use the show databases; command.

wp-ops@seebylooking:~$ sudo mysql↵
[sudo] password for wp-ops: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30200
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;↵
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> exit↵
Bye
wp-ops@seebylooking:~$

There are lots of references to start with – here’s one:

reference: https://gist.github.com/hofmannsven/9164408

For a great initial MySQL tutorial, I recommend:

reference: https://dev.mysql.com/doc/refman/5.7/en/tutorial.html

Create WordPress Database

This is probably the easiest part of the process. The only tricky part is deciding on what name to give your database.

Some security recommendations are that you give your database some meaningless name – like a strong password. That might dissuade someone from trying to hack into your database because of it’s contents suggested by it’s name.

Personally – I’m more worried about ease of use and understanding, so I tend to name my WordPress databases: wp_database

Creating the database takes tree easy steps:

  • Start a MySQL session using your root account.
  • Use the create database command.
  • Exit your MySQL session
wp-ops@seebylooking:~$ sudo mysql -u root -p↵
[sudo] password for wp-ops: 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 32457
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database wp_database;↵
Query OK, 1 row affected (0.00 sec)

mysql> exit↵
Bye
wp-ops@seebylooking:~$

If you want to quickly verify that your database was created, you can use the show databases command.

mysql> show databases;↵
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wp_database        |
+--------------------+
5 rows in set (0.00 sec)

Create MySQL User IDs

sudo mysql -uroot -p
MariaDB/Mysql> create database wp_database;
grant all privileges on wp_database.* to 'root'@'localhost' identified by 'root-password';
flush privileges;
exit;