How to Install MySQL on Ubuntu 16.04 Instance
MySQL is an open source database management system. It uses relational database and SQL to manage its data.
We need to make sure that our system is up to date before downloading MySQL.
$ sudo apt update & sudo apt upgrade
After upgrading the system, we will install mysql-server packages.
$ sudo apt install mysql-server
You will be prompted to create a root password during to installation. Choose a secure password.
After the installation is finished, we need to start the security script to make MySQL more secure.
This will prompt you for the root password you created before. You can make the following screens as follows. For stronger passwords, you can set the "password validatio policy" to 2. Also, if you want to change root password specified during installation, you can set the "change the password for root?" settings to y for setting new root password.
Securing the MySQL server deployment. Enter password for user root: ALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 Using existing password for root. Estimated strength of the password: 25 Change the password for root ? ((Press y|Y for Yes, any other key for No) : n ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
After the secure installation proccess , we need to make sure mysql-server is running.
$ sudo service mysql status ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2017-12-11 15:04:12 UTC; 11min ago Main PID: 13748 (mysqld) CGroup: /system.slice/mysql.service └─13748 /usr/sbin/mysqld
As you can see the terminal output, mysql-server is active and running.
We can test mysql by typing :
$ mysqladmin -u root -p version Enter password: mysqladmin Ver 8.42 Distrib 5.7.20, for Linux on x86_64 Copyright (c) 2000, 2017, 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. Server version 5.7.20-0ubuntu0.16.04.1 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 12 min 50 sec Threads: 1 Questions: 124 Slow queries: 0 Opens: 206 Flush tables: 1 Open tables: 64 Queries per second avg: 0.161