
MySQL is an open-source relational database management system (RDBMS) that enables the storage, management, and retrieval of database records on a server. MySQL works as a database backend and uses the SQL (Structured Query Language) syntax to store relational data in the form of tables to enable efficient records management on a server. When combined with Debian 12, a stable and secure Linux distribution, MySQL operates seamlessly, providing a reliable and high-performance database environment. Debian 12’s robust package management system ensures easy installation, security updates, and efficient resource utilization, making it an ideal choice for deploying MySQL in production or development environments.
This article explains how to install MySQL on Debian 12, secure the database server, and enforce strong authentication policies for all database users.
Before you begin:
Deploy a Debian 12 instance on Vultr.
Access the server using SSH.
Create a non-root user with sudo privileges and switch to the user.
The MySQL database server package is not available in the default APT repositories on Debian 12. Follow the steps below to download the latest MySQL repository information package and install MySQL on your server.
Download the latest MySQL repository information package.
Visit the MySQL APT repository page to verify and download the latest script version.
Install the MySQL repository information using the file.
Reply to the following MySQL repository set up script prompts to install the latest database server sources.
mysql-8.0 and press Enter to apply the version repository information.Update the server's package index to apply the new MySQL repository information.
Install the MySQL database server package.
root database user password when prompted and press Enter.Use Strong Password Encryption (RECOMMENDED) selected and press Enter to enable password authentication for all database users on the server.View the installed MySQL version on your server.
Output:
MySQL uses the mysqld system service to manage the database server runtime processes through the systemd daemon. Follow the steps below to manage the MySQL system service and enable the database server to automatically start at boot time.
Enable the MySQL database server to automatically start at boot time.
Start the MySQL database server.
View the MySQL system service status and verify that it's running.
Output:
Based on the above output, the MySQL database server is active and running.
The MySQL root database user is actively secure on your server with the password you set earlier during the installation process. MySQL includes additional insecure defaults such as test databases and remote access to the root database user on your server. Follow the steps below to disable all insecure default configurations and secure the MySQL database server.
Run the MySQL secure installation.
Reply to the following MySQL prompts to secure your database server.
Enter the root database user to start the secure installation script and modify the database server configuration.
Enter Y and press Enter to enable the VALIDATE PASSWORD COMPONENT and ensure strict password security policies.
Set your desired MySQL database server password strength policy. For example, enter 2 and press Enter to enable the use of strong passwords on your server.
Enter N when prompted to change the root database user password, or enter Y to change the password.
Enter Y and press Enter when prompted to remove anonymous users on the database server.
Enter Y and press Enter to disable remote access to the root database user.
Enter Y and press Enter to remove the test database on your server.
Enter Y and press Enter to update the MySQL privileges table and apply your configuration changes.
Output:
MySQL uses the mysql client tool to connect and access the database server console. You can also use compatible graphical interface tools such as MySQL Workbench and PhpMyAdmin to access the MySQL database server console. Follow the steps below to access the MySQL console and perform basic SQL operations on the database server.
Log in to the MySQL console as the root database user.
Enter the root user password you created earlier when prompted.
Create a new sample database shop.
View all databases and verify that the new sample shop database is available.
Output:
Switch to the shop database.
Create a new sample table products with 4 columns to store sample data.
Insert new data to the products table with the following SQL values.
Query the products table data and verify that your values are available.
Output:
Create a new sample database user db_user with a strong password. Replace Strong@@password123 with your desired password depending on the database server policy.
Grant the db_user full privileges to the shop database.
Reload the MySQL privileges table to apply changes.
Exit the MySQL console.
Log in to the MySQL database server as the new database user db_user to test access to the shop database.
Enter the db_user user password when prompted and press Enter to access the database console.
View all databases and verify that the shop database is available.
Output:
Exit the MySQL console.
You have installed MySQL on a Debian 12 server and enabled secure authentication policies on the database server. You can create multiple database records and integrate the MySQL database server with processing applications such as PHP to securely query SQL data for use in your dynamic web applications. For more information and database server security options, visit the MySQL documentation.
0 Comments
Be the first to comment and share your perspective with the community.