In today’s guide, we are studying how to install MySQL 5.7 on an Ubuntu 20.04 (Focal Fossa) server. MySQL is one of the most commonly used database management systems. It uses the concept of relational database and has a client/server architecture. It can be installed on various operating systems, including Windows, CentOS and Debian.
Install MySQL 5.7 on Ubuntu 20.04 (Focal Fossa)
The following steps describe how to install and configure MySQL 5.7 on Ubuntu 20.04. Start by adding the APT repository for the MySQL package, and then dive into the actual package installation and configuration.
Step 1: Add MySQL APT repository in Ubuntu
Ubuntu already comes with a default MySQL package repository. In order to add or install the latest repository, we will install the package repository. Use the following command to download the repository:
sudo apt update sudo apt install wget -y wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
After downloading, install the repository by running the following command:
sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
At the prompt, select Ubuntu’s Bionic then click it is good
The next prompt shows MySQL 8.0 selected by default.Select the first option and click it is good
In the next prompt, select MySQL 5.7 Server and click it is good.
The next prompt selects MySQL5.7 by default.Choose the last one it is good then click it is good
Step 2: Update the MySQL repository on Ubuntu
Run the following command to update the system package
sudo apt-get update
Now search for MySQL 5,7 using the following command apt cache As follows:
$ sudo apt-cache policy mysql-server mysql-server: Installed: (none) Candidate: 8.0.21-0ubuntu0.20.04.4 Version table: 8.0.21-0ubuntu0.20.04.4 500 500 https://ke.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages 500 https://ke.archive.ubuntu.com/ubuntu focal-security/main amd64 Packages 8.0.19-0ubuntu5 500 500 https://ke.archive.ubuntu.com/ubuntu focal/main amd64 Packages 5.7.31-1ubuntu18.04 500 500 https://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
as you can see MySQl 5.7.31-1ubuntu18.04 Appears in the list.
Step 3: Install MySQL 5.7 on Ubuntu 20.04 Linux machine
After finding MySQL 5.7 in our system, we will install MySQL 5.7 client and MySQL 5.7 server using the following commands:
sudo apt install -f mysql-client=5.7.31-1ubuntu18.04 mysql-community-server=5.7.31-1ubuntu18.04 mysql-server=5.7.31-1ubuntu18.04
hit ÿ The key to start installing MySQL 5.7 on Ubuntu 20.04 Linux.
Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libgdbm-compat4 libmecab2 libperl5.30 libtinfo5 mysql-common mysql-community-client perl perl-modules-5.30 Suggested packages: perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make libb-debug-perl liblocale-codes-perl The following NEW packages will be installed: libgdbm-compat4 libmecab2 libperl5.30 libtinfo5 mysql-client mysql-common mysql-community-client mysql-community-server mysql-server perl perl-modules-5.30 0 upgraded, 11 newly installed, 0 to remove and 35 not upgraded. Need to get 58.1 MB of archives. After this operation, 361 MB of additional disk space will be used. Do you want to continue? [Y/n] y
Enter and re-enter the root password when prompted
Step 3: Install MySQL 5.7 safely on Ubuntu 20.04
Run the following command to protect MySQL
$ sudo mysql_secure_installation
press enter. When you are prompted for a password, please provide the root password set above.
Answer the following prompts:
Enter current password for root (enter for none): <Enter password> VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 Using existing password for root. Estimated strength of the password: 25 Change the password for root ? ((Press y|Y for Yes, any other key for No) : d Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y Thanks for using MariaDB!
Check the MySQL version.
To confirm the installed version, first, connect to MySQL using the set root password.
$ mysql -u root -p
Run the following command to display the version
$ SHOW VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.31 | +-----------+ 1 row in set (0.00 sec)
Step 4: Create MySQL user (optional, test only)
While still connected to MySQL, run the following command to create a user:
CREATE USER 'user'@'%' IDENTIFIED BY 'MyStrongPass.'; GRANT ALL PRIVILEGES ON * . * TO 'user'@'%'; FLUSH PRIVILEGES; exit
Step 5: Enable MySQL remote access (optional)
By default, MySQL remote access is disabled. To enable it, we need to edit the mysqld.cnf file as follows:
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
Find line ‘bind_addressAnd make the following changes:
# By default we only accept connections from localhost #bind-address = 127.0.0.1 bind-address = 0.0.0.0
Save the file and restart mysql
$ sudo systemctl restart mysql
Allow remote connections through the firewall
$ sudo ufw allow from <remote_IP_address> to any port 3306 $ sudo ufw enable
To access the database from a remote computer, run the following command:
$ mysql -u user -h database_server_ip -p
You have successfully installed MySQL 5.7 on Ubuntu 20.04. Check out more interesting Linux guides below:
- Install MySQL 5.7 on CentOS 8 / RHEL 8 Linux
- How to install MySQL 8.0 on Kali Linux
- How to install MySQL 5.7 on Fedora
- How to install MariaDB on Ubuntu
- How to install MongoDB 4 on Ubuntu