Install MySQL 8.0 on Ubuntu 20.04

Install MySQL 8.0 on Ubuntu 20.04

MySQL Server is a cross-platform relational database that allows to access data using SQL language. MySQL Server have different editions. Community Edition (CE) is an open-source product that released under the GPLv2 license.

This tutorial demonstrates how to install MySQL 8.0 on Ubuntu 20.04.

Install MySQL

Download Debian package (.deb) that adds and configures the MySQL repository:

wget -O mysql_all.deb https://dev.mysql.com/get/mysql-apt-config_0.8.18-1_all.deb

Install the downloaded package:

sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql_all.deb

Remove .deb package because no longer needed it:

rm -rf mysql_all.deb

Update the package lists:

sudo apt update

Install MySQL 8.0:

sudo DEBIAN_FRONTEND=noninteractive apt install -y mysql-server

Once installation is completed, we can check version:

mysql --version

We can use the following command to check if MySQL service is running:

sudo service mysql status

We can also stop, start and restart the service:

sudo service mysql stop
sudo service mysql start
sudo service mysql restart

MySQL has been installed non-interactively. Password for the root user is blank and we can connect to the server without any authentication:

sudo mysql -u root

Change password of root user by running SQL statement:

ALTER USER root@localhost IDENTIFIED WITH caching_sha2_password BY 'pwd123';

Run exit command inside the client to exit interactive mode:

exit

Now try to connect to server using password:

mysql -u root -p

Uninstall MySQL

Run the following command if you want to completely remove any package with a name that starts with mysql and anything related to it:

sudo DEBIAN_FRONTEND=noninteractive apt purge --autoremove -y mysql*

Remove GPG key:

sudo apt-key del 5072E1F5

Remove MySQL user:

sudo deluser mysql

You can also remove MySQL configuration, log files, data, and other related files:

sudo rm -rf /etc/mysql
sudo rm -rf /var/log/mysql
sudo rm -rf /var/lib/mysql*
sudo rm -rf /run/mysqld
sudo rm -rf /root/.mysql_history
rm -rf ~/.mysql_history

Leave a Comment

Cancel reply

Your email address will not be published.