How to Install MySQL 8 on Ubuntu & Debian

Summary: in this tutorial, you will learn step by step how to install 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; apt-get install

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 ( find lastest repo at https://repo.mysql.com ):

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

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

sudo apt-get install gnupg
sudo dpkg -i mysql-apt-config_0.8.23-1_all.deb

You will get option to select for what you want to add via the repository. Use the Arrow key, select MySQL Server & Cluster , then press the TAB button to select OK and hit then the Enter key.

Select MySQL server and cluster

Select the available version of MySQL Server, here in our case it was myslq-8.0. After that use the TAB to select OK and hit the Enter key.

Select Database version to install

Again Select OK and then use the TAB  to move to OK and hit the Enter key.

Select MySQL 8.0 repository for Debian 11 Bullseye

This will automatically configure the latest Debian repository of the on your Debian 11 server.

Extra info: In the future, if you want to add any additional tools using its repository or want to reconfigure it run:

sudo dpkg-reconfigure mysql-apt-config

sudo apt update

Step 4. Install MySQL

Execute the following command to start installing MySQL:

sudo apt-get install mysql-server

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 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 start 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)

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

Print Friendly, PDF & Email

Related posts:

Random posts:

%d bloggers like this: