Check this Out!Visit our social network pages for recent updates!

Installing MySQL Server on Ubuntu from its Repository

MySQL server is still the most popular database server that powers majority of the websites online based on the LAMP stack. However, many Linux distributions like CentOS, Fedora and others are moving towards MariaDB.

Running the default mysql install command will instead install MariaDB in those distributions. Ubuntu still installs MySQL server when you run apt-get install mysql-server.

How long before Ubuntu join other distributions by only supporting MariaDB? This brief tutorial shows students and users an easy way to install MySQL database server from repositories hosted by its developers.

[alert-announce]Right now, MySQL will install find without adding additional repositories in Ubuntu[/alert-announce]

Installing MySQL from its Developer’s Repository

To install MySQL from its developer’s repositories, you’ll have to install additional repositories that contain MySQL packages.

To do that in Ubuntu, go to the website below and take note of the repository package.

https://dev.mysql.com/downloads/repo/apt/

Then take note of the package for Ubuntu / Debian systems.

mysql installing on ubuntu

After taking notes of the current package name, continue below to install it on Ubuntu.

Downloading MySQL Repository Package

Now that you’ve got the repository package name, run the commands below to download the package, replacing the version number with the highlighted value below.

wget https://dev.mysql.com/get/mysql-apt-config_0.8.0-1_all.deb

Once the file is downloaded, run the commands below to install the repository package.

sudo dpkg -i mysql-apt-config_0.8.0-1_all.deb

When you run the commands above, follow the wizard to install the version of MySQL you wish to install. You may also be able to try a preview version of MySQL as shown in the image below.

installing MySQL server

Installing MySQL Server

After installing the MySQL repository package,  you can install MySQL directly via apt-get command. To do that, run the commands below to install the server.

sudo apt-get install mysql-server

When you run the commands above, you’ll be shown packages that will be installed on your system. To continue, click Y for Yes and continue.

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7
mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7
mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7
mysql-server-core-5.7
0 upgraded, 9 newly installed, 0 to remove and 48 not upgraded.
Need to get 19.7 MB of archives.
After this operation, 170 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Managing MySQL Server

After installing MySQL server, the command below secures the database server by enabling stronger password, deleting the test database and disabling remote root login.

sudo mysql_secure_installation

Follow the guide below to answer the prompts.

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: n
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
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) : y
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

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.

Next, the commands below stop, enable and start MySQL server

sudo systemctl stop mysql.service

sudo systemctl enable mysql.service

sudo systemctl start mysql.service

This is how to install and manage MySQL database server on Ubuntu from the developer’s repository.

Enjoy!