MySQL is the most widely used database server for websites and applications such as WordPress, WooCommerce and custom software. On a Linux server you install MySQL via the package manager, then create users and databases, and secure the installation with a few basic settings. In this article, you’ll walk step by step through installation, management, security and maintenance of MySQL on Linux.
Installing MySQL on Linux
The installation of MySQL differs slightly per distribution, but the principle is the same everywhere: you use the package manager to download the server packages and then start the service.
Update the package list
Run sudo apt update on Debian/Ubuntu, or sudo dnf check-update on CentOS/AlmaLinux, so you install the latest package versions.
Install the MySQL server
Install the server package with sudo apt install mysql-server (Debian/Ubuntu) or sudo dnf install mysql-server (RHEL-based).
Start and enable the service
Start the service with sudo systemctl start mysql and make sure it starts automatically with sudo systemctl enable mysql.
Check the status
Check with sudo systemctl status mysql whether the server is running before continuing with configuration.
On a shared or managed hosting environment, you don’t need to perform these steps yourself: the database engine is already set up and you manage databases via a control panel such as Plesk.
Managing databases and users
After installation, log in to the MySQL shell with mysql -u root -p. From there you manage databases and users with SQL commands.
CREATE DATABASE mysite;creates a new database.CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';creates a new user.GRANT ALL PRIVILEGES ON mysite.* TO 'user'@'localhost';grants the user full rights to that database.FLUSH PRIVILEGES;ensures the privilege changes take effect immediately.SHOW DATABASES;shows all databases present on the server.
If you’re working in Plesk, you can also perform these steps via the graphical interface under the databases section, including linking a database to a specific website.
Securing MySQL
A default MySQL installation is not automatically optimally secured. After installation, run through the security script and apply a number of basic rules.
Run the security script
Run sudo mysql_secure_installation to replace a weak root password, remove anonymous users, and delete test databases.
Restrict external access
Only allow remote access to MySQL if truly necessary, and if so, limit it to specific IP addresses via the firewall.
Grant minimal privileges
Give applications only the privileges they need, instead of using ALL PRIVILEGES by default.
Use strong passwords
Use long, unique passwords per database user and store them securely, for example in a password manager.
Maintenance and backups
A database also requires ongoing attention after installation. Regular maintenance prevents performance problems and data loss.
- Back up your databases daily, preferably automated and stored in a location other than the server itself.
- Periodically check the log files for error messages or slow queries.
- Update MySQL regularly via the package manager to get security updates.
- Monitor disk space, as a full database partition can cause the entire server to crash.
At Tandata, databases run on NVMe storage and automatic daily backups are made, so that in case of problems you can quickly revert to a working version without having to set this up yourself.
If you’re considering switching from another provider to an environment where this management is already taken care of, check out the options to switch to Tandata. Detailed explanations of specific settings can also be found in the knowledge base.
Frequently asked questions
What is the difference between MySQL and MariaDB?
MariaDB is a fork of MySQL and is largely very compatible. For most websites and CMS systems, it makes little difference which one you use, although some advanced features and optimizations differ.
How do I manually back up a MySQL database?
Use the command mysqldump -u user -p databasename > backup.sql to create a full export of a database.
Can I manage MySQL without the command line?
Yes, via a control panel such as Plesk you manage databases, users and privileges through a graphical interface, without having to type SQL commands yourself.
How do I fix an ‘access denied’ error in MySQL?
Check whether the username, password and granted privileges on the correct database are correct, and always run FLUSH PRIVILEGES; after making changes.
Does every website need its own database?
It is recommended to use a separate database and user for each website. This limits the damage if something goes wrong on one site and keeps your environment organized, especially if you host multiple projects within your web hosting.
Conclusion
Installing MySQL on Linux takes just a few commands, but the real work lies in proper user management, security and structural maintenance. With the right privileges, a secured installation and reliable backups, you keep your databases stable and secure. If you’d rather hand off this management to an environment with Plesk, NVMe storage and daily backups, check out the hosting options.