How To Install MySQL Server on Ubuntu

This brief tutorial shows student and new users how to install MySQL database server on Ubuntu 18.04 | 16.04.

For those who don’t know, MySQL is a database server. Database servers are programs that provide database services to other programs or computers. They store data for applications and services.

Many of the content management systems like WordPress and Joomla use database servers to store content. So if you’re going to be using these applications to run your websites, learning how to install MySQL database server may come in handy someday.

If you’re a student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use..

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices.

When using Ubuntu, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using the system to get work done.

Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses..

To get started with installing MySQL on Ubuntu, follow the steps below:

Step 1: Preparing Ubuntu Server

Before installing programs and packages on Ubuntu systems, the first thing you’ll always want to do is update the servers. To do that, run the commands below.

sudo apt-get update

Step 2: Install MySQL Database Server

After updating your systems, run the commands below to install MySQL database server. The commands install the server as well as MySQL database client.

sudo apt-get -y install mysql-server mysql-client

When you run the command above, it will install MySQL packages and prompt you to setup a password for the root user to manage the database server. Type and confirm a new password for the root user on the screen that looks like the one below.

Ubuntu MySQL password prompt screen

After installing MySQL server, these commands below allow you to stop, start and enable the server to automatically start up when you reboot your systems.

sudo systemctl stop mysql
sudo systemctl start mysql
sudo systemctl enable mysql

Also, don’t forget to run the commands to secure the server.. this allows you to enable strong password policy, change the root password to something strong, remove anonymous users, disallow the root from logging in remotely and more.

Run the command below to secure MySQL

sudo mysql_secure_installation

You’ll be prompted with the questions below. Answer them as shown below.

Securing the MySQL server deployment.

Enter password for user root:

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

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
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

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
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...

- Removing privileges on test database...

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

All done!

To logon to the server, run the commands below.

mysql -u root -p

You’ll be prompted for the root password you created earlier. Type it to continue.


You may also like the post below:

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.