Now that we have a Web server up and running and PHP installed and integrated with the webserver, we 1
need to install the last component of the LAMP stack which is the MySql database server. 2
It will store and manage the data for our Web applications. 3
MySQL is easy to use, fast and scalable. 4
I'm installing the MySQL server using apt: apt install MySQL -server. 5
Once the installation is complete, the MySQL server will start automatically. 6
You can check it like any other service by running: systemctl status mysql 7
It's running! By the way, the daemand process that’s running is called mysqld. 8
This is the name of the process! Out of the box, MySQL is not very secure so it’s recommended to 9
run a security script that comes pre-installed with MySQL. 10
The script will remove some insecure default settings and lock down access to the database server by 11
removing some MySQL accounts and setting the admin password. 12
So I'm executing: mysql_secure_installation 13
In the first step is asking me if I want to use the “validate password plugin” which is used to test the strength 14
of the MySql users' passwords. 15
I'm choosing, yes. 16
And there are 3 levels of password strength. I’d recommend you to choose the strongest level of the 17
password. For this lab 18
I'll choose one. In the next step 19
I'm asked to set the password for the MySQL root user. 20
This is only a MySQL account named root that has nothing to do with the Linux system 21
privileged user called root. 22
It's another user. 23
It will have all the rights on the database server, so it's important to keep it secure. 24
I'm setting its password. 25
Next, I’m asked to remove an anonymous user that exists and I’m answering yes. 26
I’m restricting root user access to the local machine and I’m removing the test database as well. 27
And finally, I'm answering yes, when I'm asked if I want to reload the privilege tables. 28
It's all done! 29
Let's test the communication with the MySQL server using the command line. I'll run the MySQL command, 30
which is a MySQL client, to connect to the MySQL server. 31
This MySQL client belongs to MySQL package 32
we've installed: mysql -u and the user I'm connecting to the server with, I'm running the command 33
as the root system user and I'm logging into the server using the root mysql account (see the 34
-u root option). 35
And I' m in. 36
See that it didn’t ask for a password since I ran the command as root. 37
No, I can manage the server using sql statements. 38
Note that in the latest version of mysql, you cannot authenticate as mysql root user, by providing 39
a password; you simply run the mysql command 40
as the system root and you are in; And if you want to authenticate to the server using an external program such 41
as phpmyadmin you have to create a dedicated MySQL user for that application. 42
Now the LAMP stack is complete. There’s the Apache webserver up and running, the MySql database engine was installed 43
and it’s running and the PHP scripting language is integrated into Apache and can query the database used 44
by web apps.