Install MySQL on Ubuntu

I’ll cover how to install MySQL Server on Ubuntu 18.04 Server. MySQL is a popular and widely used relational databases amongst developers, especially Linux based development projects.

Many developers prefer to use Ubuntu servers for their deployment servers, although a statement like that is obviously going to be met with some backlash from the Linux community and like any community people will have a difference of opinion. Personally, Ubuntu is my distribution of choice.

Installing mySql on Ubuntu servers is a relatively simple task, becasue mySql is available in the Ubuntu apt repository, which means it can be installed via the terminal as follows.

Advice

In this post we assume you are not logged in as root, and therefore require to elevate your privelege to the root user. If you are logged in as root, simply omit sudo from the commands

Shell

We can now install mysql

Shell

Depending on the installation process and package version you may be prompted to provide some additional information. I have noticed this has varied over the past few months so it is difficult to document definitively.

Once the installation is complete simply check the status of the service.

Shell

The mysql services for Ubuntu should be configured to start automatically. If not you can do this as follows.

Shell

Login into mySql Console

MySQL root user on Ubuntu does not have password and its use auth_socket plugin to authenticate the root user. You can only login to the MySQL root using the system root account or using the sudo command:

Shell

If you would like to set mysql root password, run the ALTER USER command as follows:

Shell

Access mysql server external

One of the more common problems that users run into when trying to set up a remote MySQL database is that their MySQL instance is only configured to listen for local connections. This is MySQL’s default setting, but it won’t work for a remote database setup since MySQL must be able to listen for an external IP address where the server can be reached. 

In my case I have mysql installed on my Local network using my Proxmox virtual server environment. So I need to enable access to mysql from other machines on the network. By default mysql server binds itself to localhost (127.0.0.1) so you will not be able to access it externally.

We will need to edit the configuration to edit bind address value

Shell

Summary

The above presented easy to follow guide to installing mySQL on Ubuntu. We did not cover the more complex security and administration process which you should bear in mind once you have installed the server.

Latest posts by Gary Woodfine (see all)