1

How To Install MySQL on Ubuntu 18.04

In this article, I will show you how to install MySQL on Ubuntu 18.04 server and do the Initial configuration including secure installation and creating DB and user.

Prerequisites

One Ubuntu 18.04 server with a non-root user with sudo privileges.

Installing MySQL

To Install, Update the package index first by running

$ sudo apt update

Install Mysql server and client

$ sudo apt install mysql-server
$ sudo apt install mysql-client

This will install MySQL packages. Check the MySQL is running by

$ sudo systemctl status mysql

You should see output similar to the following.

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2019-12-14 11:39:09 CET; 1 weeks 6 days ago
  Process: 1785 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
  Process: 1467 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 1787 (mysqld)
    Tasks: 40 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─1787 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Dec 14 11:38:48 test-server systemd[1]: Starting MySQL Community Server...
Dec 14 11:39:09 test-server systemd[1]: Started MySQL Community Server.

If MySQL isn’t running, start the service with sudo systemctl start mysql.

Configuration

You have successfully installed MySQL, but nothing configured. You can run the initial configuration using sudo mysql_secure_installation. It is a shell script available on Unix systems and enables you to improve the security of your MySQL. You can achieve,

  • set a password for root accounts.
  • remove root accounts that are accessible from outside the localhost.
  • remove anonymous-user accounts.
  • remove the test database, which by default can be accessed by anonymous users.

Read the instructions and proceed

Securing the MySQL server deployment.


VALIDATE 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) :

 ... 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) :

 ... skipping.


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) :

 ... skipping.
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) :

 ... 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) :

 ... skipping.
All done!

Once the secure installation is completed, try to login with the new root password. mysql -u root -p. and you should land on MySQL prompt mysql>.

All new version of MySQL intallation in Ubuntu not required password to access mysql prompt if the user is running the mysql command as root or sudo. Mysql installation will create a debian-sys-maint user and password. You can grab the details from  /etc/mysql/debian.cnf 

The debian-sys-maint user is by default a root equivalent. It is used by certain maintenance scripts on Debian systems, and as a side-effect, allows users with root access on the box to view the plaintext password in /etc/mysql/debian.cnf

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *