DevOps
π MySQL 8.0 Installation Guide for Ubuntu: Your Complete Walkthrough!
Complete guide to installing MySQL on Ubuntu Server. Perfect for beginners with step-by-step instructions, security tips, and configuration basics. β±οΈ 15-min setup!
Shashikant Dwivedi
Hey there, database enthusiasts! π’οΈ Today, we're diving into setting up MySQL, the powerhouse relational database that's been a backbone of web applications for years. Don't worry β I'll walk you through this step-by-step!
β±οΈ Estimated setup time: 10-15 minutes
First Things First: System Update π«
Let's get your system refreshed and ready:
sudo apt update
Installing MySQL Server π§
Time to bring MySQL into your world:
sudo apt install mysql-server
Starting and Enabling MySQL Service π¦
Let's get MySQL up and running:
sudo systemctl start mysql.service
sudo systemctl enable mysql.service
π‘
Pro tip: The 'enable' command ensures MySQL starts automatically after server reboots.
Initial MySQL Configuration π
Access MySQL as the root user:
sudo mysql
Now, we'll set a secure root password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
exit
β οΈ
Important - Replace 'password' with a strong, unique password!
Securing Your MySQL Installation π‘οΈ
TheΒ mysql_secure_installationΒ wizard is your first line of defense. Let's break down each step:
1. Password Validation Component π
When prompted:
Would you like to setup VALIDATE PASSWORD COMPONENT?
Press y|Y for Yes, any other key for No:
- Choose 'y' to enable enhanced password security
- You'll be presented with three password strength levels:
- LOW: Length >= 8
- MEDIUM: Length >= 8, includes numeric, mixed case, and special characters
- STRONG: Length >= 8, includes numeric, mixed case, special characters, and dictionary check
Password Strength Selection
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
- Recommended: Choose 1 (MEDIUM) or 2 (STRONG)
- Provides robust protection against weak passwords
2. Root Password Configuration π
- The wizard will assess your existing root password strength
- You'll be given the option to change the root password
- If your current password is weak, strongly consider changing it
3. Anonymous User Removal π₯
Remove anonymous users?
- Always choose 'y' (Yes)
- Prevents unauthorized access to your MySQL server
- Anonymous users can log in without a specific account
- Critical for preventing potential security vulnerabilities
4. Remote Root Login Restriction π
Disallow root login remotely?
- Always choose 'y' (Yes)
- Prevents potential brute-force attacks
- Ensures root access is only possible from localhost
- Best practice for server security
5. Test Database Removal π§ͺ
Remove test database and access to it?
- Choose 'y' (Yes)
- Removes the default test database
- Eliminates unnecessary access points
- Follows the principle of least privilege
6. Privilege Table Reload π
- Automatically reloads privilege tables
- Ensures all security changes take effect immediately
π¨ Security Best Practices
- Use a strong, unique password
- Enable password validation
- Disable remote root login
- Remove anonymous users
- Remove test database
Helpful Things to Know π
- Configuration file:Β
/etc/mysql/mysql.conf.d/mysqld.cnf - Default port: 3306
- Data storage:Β
/var/lib/mysql - Log files:Β
/var/log/mysql
Verifying Installation β
Check your MySQL version:
mysql --version
First-Time Connection π
Connect to MySQL:
mysql -u root -p
Enter the password you set earlier.
Security Note π¨
Always use strong, unique passwords and follow best practices:
- Use complex passwords
- Limit root access
- Create specific user accounts for applications
- Regularly update and patch your MySQL server
Troubleshooting π οΈ
If you encounter issues, check the log file:
sudo tail -f /var/log/mysql/error.log
That's it! π Your MySQL server is now up and running.
β±οΈ Total setup time: Approximately 15 minutes
Got questions? Are you running into issues? Drop a comment below, and I'll help you out!

Written by Shashikant Dwivedi
Engineer, occasional writer, full-time noticer. Based in Prayagraj, India. New essays land roughly twice a month.
Keep reading
Adjacent essays.

DevOps
How to Install Redis on Ubuntu Server and Enable Remote Access
Sep 1, 2025 Β· 4 min

DevOps
Creating PostgreSQL Users: A Quick Setup Guide π
Jan 1, 2025 Β· 3 min

DevOps
π PostgreSQL Installation Guide for Ubuntu: Your Complete Walkthrough!
Jan 1, 2025 Β· 2 min
The newsletter
New articles in your inbox.
Occasional articles on engineering, tooling, and software development practices. No marketing, no fluff β just the article, when it's ready.
Unsubscribe with one click. Your email never leaves the list.