Step 1 : Download the required tar package from the MySQL site.
dpkg are available for the MySQL APT repository or from the MySQL Developer Zone’s download area.
cd ~
wget –c https://repo.mysql.com/mysql-apt-config_0.8.14-1_all.deb
Step 2 : Add MySQL Apt Repository
Install the repository package using below command:
sudo dpkg -i mysql-apt-config_0.8.14-1_all.deb
Select OK
Step 3 : Update MySQL Repository
In the terminal, enter the following:
sudo apt-get update
Step 4 : Install MySQL
sudo apt-get install mysql-server
Next, you’ll we prompted to enter and confirm a root user and password for the MySQL database.
The default of Use Strong Password Encryption is recommended, so hit ENTER to choose it.
The installation process will continue until completion.
If you got following error:
mysql-server : Depends: mysql-community-server (= 8.0.18-1ubuntu18.04) but it is not going to be installed
You need to include the “Universe” repository.
sudo add-apt-repository universe
sudo apt-get update
After that, attempt mysql-server installation and it will be fine.
Step 5 : Configure Security
To install the MySQL security script, enter:
sudo mysql_secure_installation
This will ask you for the MySQL root password that you set during installation. Type it in and press ENTER
You will be asked to opt VALIDATE PASSWORD PLUGIN or not
Now we’ll answer a series of yes or no prompts. Let’s go through them:
- Change the password for root ?
- Remove anonymous users?
- Disallow root login remotely?
- Remove test database and access to it?
- Reload privilege tables now
Step 6 : Start, Stop, Restart, Status of MySQL Service
To start MySQL Service
sudo systemctl start mysql
To stop MySQL Service
sudo systemctl stop mysql
To restart of MySQL Service
sudo systemctl restart mysql
To check status of MySQL Service
sudo systemctl status mysql
To start at system boot time
sudo systemctl enable mysql
Step 7 : Test MySQL
Use below command to login MySQL database
mysql -u root -p
Enter password
To list all databases on a MySQL server host, use the SHOW DATABASES command:
SHOW DATABASES;