Install MySQL on Ubuntu

Created with Sketch.

Install MySQL on Ubuntu

Summary: in this tutorial, you will learn step by step how to install MySQL 8.0 on Ubuntu.

Step 1. Update package index

Execute the following command to update the local packages index with the latest changes made in the repositories:

sudo apt update

Step 2. Upgrade packages

Type the following command to upgrade the system:

sudo apt upgrade

Step 3. Configure MySQLPPA

MySQL provides an APT repository for install MySQL server and tools. You need to add this MySQL repository to your system’s package source list.

First, download the repository package using the wget command:

wget -c https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb

Code language: JavaScript (javascript)

Then, install the MySQL repository package using the following dpkg command:

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

Code language: CSS (css)

Step 4. Install MySQL

Execute the following command to start installing MySQL:

sudo apt-get install mysql-server

Code language: JavaScript (javascript)

It will prompt for the root‘s password. Enter a secure password and continue.

Step 5. Secure MySQL server installation

Execute the following command to adjust security to the MySQL Server:

sudo mysql_secure_installation

It will prompt you some security options that you should choose in order to secure the MySQL server:

  • Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Step 6. Manage MySQL Server via Systemd

Typically, MySQL service is automatically started once the package is configured. To check whether the MySQL server is up and running or not, you use this command:

sudo systemctl status mysql

If you found that the MySQL server does not automatically start, you can use the following command to start it:

sudo systemctl status mysql

And start it automatically at system startup:

sudo systemctl enable mysql

Step 7. Connect to MySQL server

To connect to the MySQL Server, use this command:

sudo mysql -u root -p

It will prompt for the password of the root account. You enter the password and press Enter, the following command will show if the password is valid:

mysql>

Use the SHOW DATABASES to display all databases in the current server:

mysql> show databases;

Here is the output:

+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.05 sec)

Code language: JavaScript (javascript)

In this tutorial, you have learned step by step how to install MySQL 8 on Ubuntu.

Leave a Reply

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