How to Install MySQL Database on Ubuntu 18.04 / 20.04 via Terminal?
To install MySQL on Ubuntu operating system, simply follow the steps below:
- Open your terminal and run the following update command:
- Run the following command to install MySQL:
- When you see "Do you want to continue? [Y/n]" during the installation process, type y and hit enter.
- Next, configure MySQL security, by running the following command:
- Again, when you see "Press y|Y for Yes, any other key for No:", press y and hit enter.
- Next, you will need to configure your MySQL password validation policy. If you want the MySQL database accessing user's password to be strong then select 2. I am selecting 1 which is medium.
- Next enter password of your choice.
- When you see "Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No)", press y and hit enter.
- When you see "Remove anonymous users? (Press y|Y for Yes, any other key for No)", press y and hit enter.
- When you see "Disallow root login remotely? (Press y|Y for Yes, any other key for No), press y if you do not want to allow access to your MySQL from remote computer else press n and hit enter.
- Press n when you see "Remove test database and access to it? (Press y|Y for Yes, any other key for No)" and hit enter.
- When you see "Reload privilege tables now? (Press y|Y for Yes, any other key for No)", press y and hit enter.
- Next, open MySQL in your terminal by using the following command:
- Run the following MySQL command to update root user's password (I am updating my MySQL root user's password to TestPass123$):
- Next, run the following MySQL command to flush privileges:
- Now, after installing MySQL, lets install MySQL Workbench by running the following command one by one:
sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'TestPass123$';
FLUSH PRIVILEGES;
sudo apt update
sudo apt install mysql-workbench
Press
Installation of MySQL is complete.