How To Install MySQL on Ubuntu 22.04
Step 1: Update Your System
Ensure your system is updated before installing MySQL.
sudo apt update && sudo apt upgrade -y
Step 2: Install MySQL
Use the following command to install MySQL Server.
sudo apt install mysql-server -y
Step 3: Secure MySQL Installation
Run the security script to enhance security settings.
sudo mysql_secure_installation
Step 4: Create a Dedicated MySQL User and Grant Privileges
Login to MySQL:
sudo mysql
Create a new user and grant privileges:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Exit MySQL:
EXIT;
Step 5: Testing MySQL
Check MySQL status:
sudo systemctl status mysql
Login with the new user:
mysql -u newuser -p