Installing MySQL Server
Execute these commands to instal MySQL on Ubuntu 20.04:
sudo apt update
sudo apt install mysql-server
Verify the installation and check the service status:
mysql --version
sudo systemctl status mysql
Securing MySQL Installation
Run the security script to configure basic security settings:
sudo mysql_secure_installation
This interactive script will guide you through:
- Setting up password validation plugin
- Changing root password
- Removing anonmyous users
- Disabling remote root login
- Removing test database
- Reloading privilege tables
Modifying Root Authentication
For MySQL 8.0+, use this method to udpate root credentials:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';
FLUSH PRIVILEGES;
Restart the MySQL service to apply changes:
sudo systemctl restart mysql
Connecting to MySQL
Access the MySQL shell with:
mysql -u root -p
Once connected, you can manage databases:
SHOW DATABASES;
CREATE DATABASE sample_db;
DROP DATABASE sample_db;