This article guides you on how to install and configure MySQL optimization on Ubuntu 22.04 and 20.04 Linux. By doing so, you will prevent unexpected MySQL errors and enhance the performance of your web/app.
How to install and optimization MySQL on Ubuntu 22.04 | 20.04 & Linux
Mysql server uses InnoDB, a storage engine for the MySQL database management system, and MariaDB replaces MyISAM.
Step 1. Update the system and install the latest MySQL
At the time of this write, the latest MySQL version available in the Ubuntu repository is MySQL version 8.0.28. To install it, run the following command:
sudo apt update && sudo apt upgrade -y sudo apt install mysql-server
Type Y to confirm the settings, then go to the MySQL security step.
Step 2. How to Secure MYSQL on Ubuntu 22.04 | 20.04
MySQL installation comes with a script called mysql_secure_installation that allows you to easily improve the security of your database server.
- Press y|Y for Yes, any other key for No: Leave blank and type Enter
- Please set the password for root here: Enter the password and confirm
- The next steps Enter
Yto delete unnecessary users, and database tests.
Step 3. Config and Optimization MYSQL on Ubuntu Linux
First, to determine which file is configuring for MYSQL run the following command.
mysqld --help --verbose | head -n13
As you can see in the image below the config file is set up in the order of /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf, you can modify the config in any of the files.
Here I will set up the file
/etc/mysql/my.cnf, download the file
my.cnf link below and replace your config. (my.cnf file is collected from a number of experts)
sudo gedit /etc/mysql/my.cnf
Link download: https://gist.github.com/fevangelou/fb72f36bbe333e059b66
Next, after changing the config you can check if the config has any problems with the following command. If there is an error you will receive a notice and recheck the value of that config.
mysqld --defaults-file=/etc/mysql/my.cnf --validate-config
Restart MYSQL after the config change is done.
sudo service mysql restart
Step 4. How to use MYSQL on Linux Ubuntu
How to create a database, username, import… similarly you can read this article on how to install MYSQL on Ubuntu 20.04 with Percona 5.7 from step 4.
Above are the steps on how to optimize MySQL on ubuntu 22.04 | 20.04 & Linux and usage statements. Hope it helps you.