MySQL is a relational database system owned by Oracle Corporation and it has been a part of the Ubuntu repositories right from its earlier versions. The release cycles of Ubuntu and MySQL do not exactly match; hence in some older Ubuntu versions, the latest MySQL version will not be available in the repository.
Today, we will see how to install and configure the latest MySQL 8 on Ubuntu.
Installing MySQL 8 on Ubuntu
MySQL 8 is available in the official Ubuntu repositories starting from Ubuntu 20.04. If you are using Ubuntu 20.04 or higher, install MySQL 8 with the following command:
$ sudo apt install mysql-server
This will install all packages; including MySQL Client, MySQL Server, and all other required packages.
If you are using an Ubuntu version lower than 20.04, you need to first run the following command to download the MySQL apt repository deb file:
$ sudo wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.17-1_all.deb
Now, install the downloaded deb file using the following command. It will ask for the input of packages to be made available for install. Mark on ‘MySQL Server and Cluster’ and press the right arrow key to move the cursor on ‘Ok’, and hit Enter.
$ sudo dpkg -i mysql-apt-config_0.8.17-1_all.deb
Then choose the MySQL version from the next popup and mark on MySQL 8 and hit Enter.
You will once again be directed to the earlier screen. Choose ‘Ok’ from the list, and hit Enter.
Next, install MySQL 8 by simply running the following command, which will install MySQL Server, Client as well as other dependent packages.
$ sudo apt update $ sudo apt install mysql-server
During MySQL Server installation, it will ask you to set a root password.
Next, set the default MySQL authentication method.
Finally, verify if MySQL has been installed by connecting to MySQL as the root user. Make sure to enter the root password that you have set during the installation.
$ sudo mysql -u root -p
In the MySQL prompt, run the following query to confirm if the MySQL server is working:
mysql> show databases;
Thus, MySQL has been installed and properly working.
Securing MySQL Server in Ubuntu
The installation of MySQL also installs a security script, which configures the MySQL installation for maximum security against the most common concerns.
$ sudo mysql_secure_installation
It will prompt for options like removal of anonymous users, remote login, etc. Enter the appropriate inputs: eg. password strength level, etc. Enter ‘y’
to configure the corresponding options.
The MySQL installation is now complete and the database is ready to use!
If you want to uninstall MySQL Server, you can read our guide – Completely Uninstall MySQL Server in Ubuntu
Conclusion
In this article, we have seen how to install MySQL 8 in Ubuntu. Let us know your thoughts and questions in the comments below.
In the 2nd step below:
I had to use:
to have write permissions for the file. Was installing on Linux Mint 20.x. Hope that helps someone.
@Denis,
I have updated the command with the link to download the latest MySQL APT repository…