A beginner’s guide to installing and configuring MySQL database on your Linux VPS.
Introduction
MySQL is a powerful and widely used database management system. This guide will help you install and configure MySQL on your Linux VPS, providing a robust solution for managing your databases.
Step 1: Install MySQL
Installing MySQL is the first step towards setting up your database management system on your Linux VPS.
Update Package Lists:
Before installing MySQL, it’s essential to update your package lists to ensure you get the latest version of the software:
sudo apt update
This command updates the package lists for the repositories and ensures that you have the latest information on available packages.
Install MySQL:
Install the MySQL server package using the following command:
sudo apt install mysql-server -y
This command installs MySQL and confirms the installation with the -y
flag, which automatically answers ‘yes’ to any prompts.
Step 2: Secure MySQL Installation
Securing your MySQL installation is crucial to protect your database from unauthorized access and potential vulnerabilities.
Run the Security Script:
MySQL includes a security script that helps you improve the security of your installation:
sudo mysql_secure_installation
Follow the Prompts:
During the execution of the security script, you will be prompted to:
- Set a root password.
- Remove anonymous users.
- Disable remote root login.
- Remove the test database. Follow these prompts to enhance the security of your MySQL installation.
Step 3: Create a MySQL User
Creating a MySQL user with specific privileges allows you to manage your databases securely.
Access MySQL Shell:
Log in to the MySQL shell using the following command:
sudo mysql
This command opens the MySQL shell where you can execute SQL commands.
Create a New User:
In the MySQL shell, create a new user and grant them the necessary privileges:
CREATE USER 'newuser'@'localhost'
IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
creates a new user namednewuser
with the specified password.GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
grants all privileges to the new user.FLUSH PRIVILEGES;
reloads the privilege tables to ensure that the changes take effect.EXIT;
exits the MySQL shell.
Conclusion
MySQL is now installed and configured on your Linux VPS. You can start creating and managing databases, taking advantage of MySQL’s powerful features for your applications and projects. By following this guide, you’ve ensured that your MySQL installation is secure and ready for use.