SKDBLOG

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
3 min read
πŸš€ MySQL 8.0 Installation Guide for Ubuntu: Your Complete Walkthrough!
DevOps03 MIN

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:

bash
sudo apt update  

Installing MySQL Server πŸ”§

Time to bring MySQL into your world:

bash
sudo apt install mysql-server  

Starting and Enabling MySQL Service 🚦

Let's get MySQL up and running:

bash
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:

bash
sudo mysql  

Now, we'll set a secure root password:

bash
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:

bash
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

bash
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 πŸ‘₯

bash
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 🌐

bash
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 πŸ§ͺ

bash
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:

bash
mysql --version  

First-Time Connection πŸ”Œ

Connect to MySQL:

bash
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:

bash
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.

All writing β†’

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.