How to install MYSQL on Ubuntu 20.04 with Percona 5.7
This article shows how to install MySQL on ubuntu 20.04, how to configure MySQL, and the whole way to use MySQL on ubuntu with Percona 5.7.
1. Install GnuPG, GNU Privacy Guard:
GnuPG is a complete and free implementation of the OpenPGP standard as defined by RFC4880 (also known as PGP). You can refer here: https://gnupg.org/. Run the command below to install gnupg2.
sudo apt-get install gnupg2
2. Download and Install MYSQL Percona 5.7 on Ubuntu 20.04
The command below will download the Percona deb file and update the percona-release.list
repository file inside the /etc/apt/sources.list.d directory.
You can also refer to the guide from Percona homepage: https://www.percona.com/doc/percona-server/5.7/installation/apt_repo.html#standalone-deb
cd /tmp wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb sudo apt-get update && sudo apt-get upgrade sudo apt-get install percona-server-server-5.7
After running the command to install Percona 5.7, the installation interface appears, in this step, I leave the password box blank, and OK, you can set a password if you want. Wait for percona to be installed successfully, enable it, and allow it to start with the system.
sudo systemctl enable mysql
3. Config MYSQL Percona and Security on Ubuntu 20.04 LTS
Run the command below and do the same as shown in the image to configure and secure MYSQL on Ubuntu 20.04 LTS.
sudo mysql_secure_installation
4. How to login MYSQL and create a database, username
Because in step 2 I did not set a password for the root user, I will log in with the command: sudo mysql
, and the commands below will create a new database and username in MYSQL.
sudo mysql (Or sudo mysql -u root -p)
CREATE DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON database_name.* TO username@localhost IDENTIFIED BY 'password'; FLUSH PRIVILEGES; \q
If there is an error with the GRANT ALL PRIVILEGES statement try with:
GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost'; FLUSH PRIVILEGES; \q
5. How to import the database on MYSQL
Method 1: Recommend this way
- Open the terminal in the directory containing the SQL file to import
- Login to MySQL
- Check and use the database you need to import
- Import as shown below.
With method 1 in this MySQL install post on ubuntu, you can see the process of importing to the database.
Method 2: Use the normal import command
mysql -u username -p database_name < file.sql
Method 3: Use PHPMyAdmin, or Adminer to import
Click Import
button, then find the MySQL file and start importing, with large MySQL files, you need to adjust some MySQL, PHP, and Nginx config.
6. Common use command in MySQL
Restart command: restart MySQL
sudo service mysql restart
Reload command: Reload configuration and do not restart
sudo service mysql reload
Stop command: shutdown/stop MySQL
sudo service mysql stop
Start command: Start MySQL
sudo service mysql start
The command to enable MySQL allow running at system startup
sudo systemctl enable mysql
Disable command: Turn off MySQL from starting with the system
sudo systemctl disable mysql
7. How to Optimize MYSQL Percona 5.7 on Ubuntu 20.04
Open the file /etc/mysql/percona-server.conf.d/mysqld.cnf
, should be opened with gedit command or opened with sublime text
Download the file mysqld.cnf
this about and edit the same config. After saving the file, run the command below to restart MySQL for the config to take effect.
sudo service mysql restart
8. How to update the database in MYSQL Percona 5.7
The following command will update the entire database for you.
sudo mysql_upgrade
9. How to remove MySQL on Ubuntu 20.04 | 22.04 & Linux
Delete, and remove MySQL cleanly from ubuntu, note back up the database before doing this
sudo apt purge 'mysql*' sudo apt remove 'mysql*' sudo apt autoremove && sudo apt autoclean sudo rm -rf /etc/mysql sudo rm -rf /var/lib/mysql
Above are the steps to guide how to install MYSQL on Ubuntu 20.04 with Percona 5.7, as well as MySQL security on Ubuntu 20.04 & Linux. If you need to install phpMyAdmin on Ubuntu to manage MySQL, you can proceed by reading the available article we provide.
– Advertising –