Summary: in this tutorial, you will learn step-by-step how to install MySQL 8.0 on Ubuntu 22.0 (codename: jammy).
Before you begin, ensure you have root or sudo privileges on your Ubuntu system.
Step 1. Update APT Package List
Update the APT package list to ensure that you have the latest information about available packages:
sudo apt update
Step 2. Install MySQL Server
To install MySQL, use the apt
package manager. You can install MySQL using the apt package manager by running the following command:
sudo apt install mysql-server
Step 3. Enable MySQL service to auto-start on reboot
sudo systemctl enable mysql.service
Code language: CSS (css)
Step 4. Start MySQL Service
sudo systemctl start mysql.service
Code language: CSS (css)
Step 5. Check the status of MySQL Service
systemctl status mysql.service
Code language: CSS (css)
Note that you can press q
to exit the message.
Step 6. Log in to MySQL and change the root’s password
First, log in to the MySQL server using the following command:
sudo mysql
It’ll take you to the mysql command line:
mysql>
Second, change the password of the root’s account:
ALTER USER root@localhost
IDENTIFIED WITH mysql_native_password
BY '<YOUR_PASSWORD>';
Code language: CSS (css)
You should store the password in a secure place for logging in to the MySQL server later.
Third, exit the MySQL database server:
exit
Code language: PHP (php)
Fourth, attempt to log in to the MySQL database server with the new password:
mysql -u root -p
It’ll prompt you to enter a password. Please use the password that you entered in the previous step:
Enter password:
If you enter the password correctly, you’ll be logged in to the MySQL database server.
mysql>
Before going to the next step, exit the mysql client tool:
exit
Code language: PHP (php)
Step 7. Secure the MySQL installation
Execute the following command to adjust the security of the MySQL Server:
sudo mysql_secure_installation
It’ll prompt you to enter the root’s password. After you enter the password correctly, you will be asked a series of questions. Press ‘Y’ or ‘N’ for the various security questions.