Hosting + Ai Website Builder + Free Domain (3 Month Free Credit)
Shop Today

Use MySQL on Linux Like a Pro: Step-by-Step Tutorial

Use MySQL on a Linux server to store, organize, and manage your data with speed and reliability. MySQL is a leading open-source relational database, widely adopted for its performance, security, and ease of integration with Linux environments.

Install MySQL on Linux

This guide explores how to use MySQL on a Linux server, giving you everything you need to get up and running: from installing and securing your database to everyday management tasks.

Prerequisites

  • A Linux server running Ubuntu, Debian, CentOS, Red Hat, or Oracle Linux.
  • Root or sudo privileges are required to install and configure software.
  • Comfort with using the terminal (command line).

Steps to Use MySQL on a Linux Server

Use MySQL on Linux to build a robust and scalable database environment ideal for dynamic web applications, enterprise systems, and data-driven solutions. MySQL is one of the most widely used open-source relational database management systems, and Linux provides a secure, high-performance platform to host it. With powerful command-line tools, wide community support, and compatibility with popular frameworks, using MySQL on Linux is a go-to choice for developers and system administrators alike.

Step 1: Install MySQL on the Linux Server

Before you use MySQL on a Linux server, start with the installation process that matches your distribution.

  • Ubuntu/Debian:
sudo apt update sudo apt install mysql-server 

This sequence refreshes the package index and installs the MySQL server from your official repositories.

  • CentOS/Red Hat:
sudo yum update sudo yum install mysql-server 

After running these commands, MySQL is downloaded and set up, ready for use.

Optionally, you can add the official MySQL repository from Oracle for the very latest version, but most users find the default repositories perfect for daily needs.

Step 2: Start and Enable MySQL Service

Once MySQL is installed, make sure it’s running and set to start every time your Linux server reboots.

Start MySQL service:

  • Ubuntu/Debian:
sudo systemctl start mysql
  • CentOS/Red Hat:
sudo systemctl start mysqld

Enable MySQL on boot:

  • Ubuntu/Debian:
sudo systemctl enable mysql
  • CentOS/Red Hat:
sudo systemctl enable mysqld

Check service status:

  • Ubuntu/Debian:
sudo systemctl status mysql
  • CentOS/Red Hat:
sudo systemctl status mysqld

Step 3: Secure Your MySQL Installation

Security is essential when you use MySQL on a Linux server. There’s a built-in script to guide you through key improvements:

sudo mysql_secure_installation

You’ll be prompted to set a strong root password, remove anonymous users, disable root login remotely, remove test databases, and reload privilege tables. Just follow the interactive steps—making your server safer in minutes.

Step 4: Test MySQL Installation

Check that MySQL is installed correctly and accessible.

Display MySQL version:

  • Ubuntu/Debian:
mysql --version
  • CentOS/Red Hat:
mysql --version
  • Connect to MySQL server as root:
sudo mysql -u root -p 

When prompted, enter your root password to access the MySQL shell and begin working with your databases.

Step 5: Basic MySQL Server Management

Now you’re ready to use MySQL on a Linux server to organize data for your applications.

  • Create a new database:
CREATE DATABASE mydatabase;
  • Create a new user:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'strong_password';
  • Grant privileges to your new user:
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost'; FLUSH PRIVILEGES;
  • List existing databases:
SHOW DATABASES;
  • Exit the MySQL shell:
EXIT;

View MySQL error logs for troubleshooting:

  • Ubuntu/Debian:
/var/log/mysql/error.log
  • CentOS/Red Hat:
/var/log/mysqld.log

Logs provide essential information about any problems or unexpected behavior.

Conclusion

To use MySQL on a Linux server, simply install the MySQL package with your system’s package manager, start and enable the service, secure your installation, and practice essential server management tasks like creating databases and users. With these steps, you have a robust foundation for organizing and storing data, whether building a simple website or a major business platform.

MySQL on Linux makes data management efficient, reliable, and ready for your future projects. For more information, visit the MySQL official documentation.

Himanshu Joshi

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top