How To Install & Manage MySQL Server In Ubuntu

MySQL is a worlds most popular open-source relational database management system that is available for all major platform. Basically It stores huge volume of data and enables you to implement database with tables, columns and indexes.

MySQL is a popular open source database management system. Most of the web applications such as WordPress, Drupal, Joomla require to use MySQL database to store various kinds of data. Though, Not all web application require MySQL database, But nowadays most of the web application use MySQL database. MySQL is a part of LAMP (Linux, Apache, MySQL, PHP/Python/Perl) and LEMP (Linux, Nginx, MySQL, PHP).

If you are on shared hosting or any managed hosting environment, You have a lot of option to manage MySQL from MySQL control panel offered by your hosting provider. Most of the shared hosting company provide cPanel that lets you use phpMyAdmin to manage all MySQL databases. cPanel also allow you to Create Database, Create new user and assign database permission to users.

But if you are on an unmanaged hosting environment, You may need to manually install MySQL database server and need some basic Linux skill to manage MySQL databases. Here in this tutorial, I’ll show you how to install MySQL server in Ubuntu.

How To Install MySQL Server In Ubuntu

I assume you have a working Ubuntu server. In this tutorial of MySQL installation, I’m using Ubuntu 16.04 x64. You also need to have access to your server, In order to access your server using SSH from Windows, You should download Putty.

The very first step in MySQL server installation is, Login to your server using SSH, If you are on windows, You can use Putty to login your server using SSH. If you still don’t have installed Apache and PHP5, You can do that later after installing MySQL. Once you have successfully logged in to your server, Now start installing MySQL server.

First thing first, You may need to update and upgrade apt using

sudo apt-get update
sudo apt-get upgrade

Now execute the main command that will download and install MySQL server to your Ubuntu server

sudo apt-get install mysql-server

By executing the command above, Ubuntu will ask you for confirmation about installing MySQL.

Install MySQL Server

Type y and hit enter to continue the MySQL installation.

Configure MySQL Server

Once you have executed the command above, You will be asked to enter password for root user. Enter the password twice and hit enter. That’s it.

You have just completed the installation of MySQL to your Ubuntu server. There are a lot of things and settings still need to do to make your MySQL server secure. If you have installed MySQL to your production server, You must need to run the following command to secure your MySQL server installation.

sudo mysql_secure_installation

After the command executed, MySQL will ask you for various security settings. Below I’ve inserted an sample terminal session:

sudo mysql_secure_installation
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:
Using existing password for root.
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

After that, your MySQL installation is secured. Now login to your MySQL server using:

mysql -u root -p

The login command will prompt for MySQL user password. Enter the user password and hit enter. The first login to MySQL server is similar to:

First time MySQL login

You have logged in to MySQL server, Now lets create a database called testdb and create a user called testuser and test_pas8o*d as user password.

CREATE USER testuser@localhost IDENTIFIED BY 'testuser';
GRANT ALL PRIVILEGES ON testdb.* TO testuser@localhost;

At this step you may want to logout from MySQL. you can do that by typing exit and hit enter.

Start, Stop & Restart MySQL Server

How to stop MySQL server:

sudo /etc/init.d/mysql stop

How to start MySQL server:

sudo /etc/init.d/mysql start

How to restart MySQL server:

sudo /etc/init.d/mysql restart

There are many ways of start, Stop and restart MySQL server in Ubuntu. Here I’ve shown the preferred way to do that.

Q: How To Check If MySQL Server is Running or not?

To check the status of your MySQL server execute the following command:

sudo /etc/init.d/mysql status

Q: Where is MySQL database server configuration file located in Ubuntu 16.04?

In Ubuntu 16.04, The MySQL database server configuration file located at /etc/mysql/mysql.conf.d/mysqld.cnf

Hope this tutorial will help you to install MySQL database server to your Ubuntu, If you have encountered an error while installing or you need help on MySQL installation, Please let us know using the discussion box below.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive website improvement tips and tutorials.


We'll periodically send useful information, tips & tutorials to improve your website performance, conversion optimization, SEO and design tweaks to make your website better.

Thank you for signing up!

Please check your email and click the link provided to confirm your subscription.

Powered by Rapidology
No Comments

Post a Comment