How to Install MySQL on Linux and Create Your First Database (Beginner-Friendly Guide)
1. What Is MySQL? (Super Simple Explanation)
Let’s keep this very easy.
MySQL is:
-
A database system that stores your data
-
A place where your apps save things like users, products, posts, etc.
-
Very fast, reliable, and free
-
Used by millions of developers
If you want to build apps, websites, or anything involving data, MySQL is essential.
2. Step 1 — Update Your Linux Server
Before installing anything, always refresh your package list.
This ensures you avoid errors later.
3. Step 2 — Install MySQL Server
Now let’s install MySQL:
After installation finishes, check the status:
If you see active (running) — MySQL is alive and working.
Press q to exit.
4. Step 3 — Secure Your MySQL Installation
MySQL includes a security script to help beginners lock down their database quickly.
Run:
You’ll be asked several questions. Here’s the easiest recommended setup:
| Question | Recommended Answer |
|---|---|
| Validate password plugin? | Yes (press Y) |
| Password level | LOW or MEDIUM (if you’re a beginner) |
| Remove anonymous users? | Yes |
| Disallow remote root login? | Yes |
| Remove test database? | Yes |
| Reload privileges? | Yes |
After this, your MySQL server is much safer.
5. Step 4 — Log In to the MySQL Console
Now let's enter the database environment.
You’ll see something like this:
You are now inside MySQL. Time to create your first database.
6. Step 5 — Create Your First Database
For beginners, let’s create a simple database called my_first_db.
In the MySQL console, type:
You just created your first real database!
7. Step 6 — Create a Database User
Instead of using the root user (which is dangerous), we’ll make a new user.
Now give that user permission to access your database:
Apply the changes:
You now have:
-
A database
-
A user
-
Permissions to manage it
Great progress!
8. Step 7 — Create a Table (Very Simple Example)
Let’s now practice creating a table inside your new database.
First, switch to your database:
Now create a simple table:
You now have a working table that can store user information.
9. Step 8 — Insert Data Into the Table
Let’s insert your first row:
Add another:
Nice and easy.
10. Step 9 — View Your Data
Check what you just inserted:
You should see:
| id | name | |
|---|---|---|
| 1 | Alice | alice@example.com |
| 2 |
| Bob |
| bob@example.com |
Your database is now fully functional!
11. Step 10 — Exit MySQL
When you’re done:
That’s it!
12. Bonus: Connect to MySQL Using the New User
Let’s test the new user you created:
Enter your password → you’re inside again.
Now try listing your databases:
You’ll see:
Perfect.
13. Bonus: Enable Remote Access (Optional for Beginners)
Only do this if you need to connect from another machine.
-
Open MySQL config:
-
Find:
Change to:
-
Restart MySQL:
-
Allow remote connections for your user:
This allows access from anywhere.
14. Troubleshooting (Beginner Friendly)
❌ Login fails
✔ Wrong password
✔ Trying to log in as root without sudo
✔ User doesn’t have privileges
❌ Can't create database
✔ You forgot the semicolon
✔ You're not logged in as root
❌ Remote access not working
✔ Firewall blocking port 3306
✔ bind-address still set to 127.0.0.1
❌ Access denied for user
✔ You forgot FLUSH PRIVILEGES
Everything has a simple fix — MySQL errors look scary but are usually easy to solve.
Conclusion
You’ve now installed MySQL, secured it, created a database, made a user, built a table, inserted data, and queried data — all as a complete beginner. This foundation will help you build real-world applications, websites, and backend systems in the future. Understanding MySQL is a major milestone for any new developer, and now you’ve taken that important step.