There are a lot of development tools you can use on Ubuntu, and one of them is MySQL. We're sure you're familiar with it, but MySQL is one of the most popular relational database management systems. It's open source, and it sits behind other products like Oracle Database, which means MySQL also works on Ubuntu. To install it, you'll just need to run a few commands in the terminal. We're here to guide you through the process.

How to install MySQL on Ubuntu

Like with many other development and technical tasks on Linux, there's something to keep in mind before you install MySQL on Ubuntu. You'll need an account with administrative (sudo) privileges to access the terminal. You'll also need a network connection. Once you pass these prerequisites, you can proceed with the steps below. Oh, and after every command, you'll have to press the Enter key.

  1. Update your packages with the command:
    sudo apt update
  2. Enter your password.
  3. Upgrade your packages with the command:
    sudo apt upgrade
  4. If prompted, press Y and then Enter.
  5. With packages upgraded, install MySQL with the command:
    sudo apt install mysql-server
  6. If prompted, enter your password, press Y and then Enter.
  7. You can then log in to MySQL Server by running the command:
    sudo mysql -u root
    Or, simply start MySQL with
    sudo systemctl start mysql.

MySQL will be installed on your machine. It could take a while, depending on your internet speed. When complete, you can check for it with the command mysql --version. At any time, you can check to see if MySQL is running by entering the command:

sudo systemctl status MySQL
 

Additional steps for MySQL configuration

Those were just the basic steps for setting up MySQL on Ubuntu. After installation, there are a few other things we suggest doing.

Secure your MySQL session

By default, you won't get a password, but you can type the command:

sudo mysql_secure_installation

From there, you can enter your password, press Y to confirm, follow the steps on your screen, and choose a password level.

Allow remote access

You can enable remote access to connect to your databases from another machine. Type the following commands:

sudo ufw enable 

sudo ufw allow mysql

Launch MySQL at reboot

If you always want your server to run each time you reboot your system, run the command:

sudo systemctl enable mysql

See users

To see all users on a database, type the following command:

SELECT User, Host, authentication_string FROM mysql.user;

We hope you found this guide helpful. If you're a developer using Ubuntu, you might also be interested in checking out our list of some of the best laptops and desktops, including ones that work well with Linux. Having the right hardware can always make your life easier.