Advertisement
linuxserver MySQL is one of the most widely used databases in the world, powering everything from small student projects to massive enterprise applications. If you're a beginner or someone who has never touched a database before, this guide is perfect for you. In this completely beginner-friendly tutorial, you’ll learn how to install MySQL on a Linux server, secure it, log in, create your first database, and run basic SQL commands.

How to Install MySQL on Linux and Create Your First Database (Beginner-Friendly Guide)

5 Min Read Verified Content
The explanations are simple, the steps are clear, and the tone is relaxed—ideal for newbies, “dummies,” or anyone starting their database journey.

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.

sudo apt update sudo apt upgrade -y

This ensures you avoid errors later.




3. Step 2 — Install MySQL Server

Now let’s install MySQL:

sudo apt install mysql-server -y

After installation finishes, check the status:

sudo systemctl status mysql

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:

sudo mysql_secure_installation

You’ll be asked several questions. Here’s the easiest recommended setup:

QuestionRecommended Answer
Validate password plugin?Yes (press Y)
Password levelLOW 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.

sudo mysql

You’ll see something like this:

Welcome to the MySQL monitor... mysql>

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:

CREATE DATABASE my_first_db;

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.

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password123';

Now give that user permission to access your database:

GRANT ALL PRIVILEGES ON my_first_db.* TO 'newuser'@'localhost';

Apply the changes:

FLUSH PRIVILEGES;

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:

USE my_first_db;

Now create a simple table:

CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), email VARCHAR(100) );

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:

INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');

Add another:

INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com');

Nice and easy.




10. Step 9 — View Your Data

Check what you just inserted:

SELECT * FROM users;

You should see:

idnameemail
1Alicealice@example.com
2
Bob
bob@example.com

Your database is now fully functional!




11. Step 10 — Exit MySQL

When you’re done:

EXIT;

That’s it!




12. Bonus: Connect to MySQL Using the New User

Let’s test the new user you created:

mysql -u newuser -p

Enter your password → you’re inside again.

Now try listing your databases:

SHOW DATABASES;

You’ll see:

my_first_db

Perfect.




13. Bonus: Enable Remote Access (Optional for Beginners)

Only do this if you need to connect from another machine.

  1. Open MySQL config:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  1. Find:

bind-address = 127.0.0.1

Change to:

bind-address = 0.0.0.0
  1. Restart MySQL:

sudo systemctl restart mysql
  1. Allow remote connections for your user:

GRANT ALL PRIVILEGES ON my_first_db.* TO 'newuser'@'%' IDENTIFIED BY 'password123';

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.


Advertisement
Back to Linuxserver