To install MariaDB on CentOS or Rocky Linux, use the dnf package manager: sudo dnf install mariadb-server. This installs MariaDB 10.5 on Rocky Linux 9 and CentOS Stream 9 (or MariaDB 10.3 on CentOS 7), after which you enable and start the service with sudo systemctl enable --now mariadb and secure it with sudo mysql_secure_installation.
Background: MariaDB vs. MySQL
MariaDB is a community-developed fork of MySQL, created in 2009 after Oracle acquired MySQL. It is designed as a drop-in replacement, meaning most commands, syntax, and client tools work identically. Rocky Linux, a CentOS replacement, and CentOS Stream both ship MariaDB as the default database server in their repositories—not Oracle MySQL. This is a deliberate choice: MariaDB is fully open source (GPL) and avoids the dual-licensing complexity of MySQL. For most users, installing MariaDB is the simplest and most compatible path on these distributions.
Prerequisites
- A CentOS 7, CentOS Stream 8/9, or Rocky Linux 8/9 system with sudo access.
- An internet connection to download packages.
- Basic familiarity with the command line.
No separate repository is needed; the default AppStream or base repositories include MariaDB. On CentOS 7, the package is in the base repository; on Rocky and CentOS Stream, it is in AppStream.
Step-by-Step Installation
- Update your system (recommended):
sudo dnf update -y(orsudo yum update -yon CentOS 7). - Install MariaDB server and client:
sudo dnf install mariadb-server mariadb -yOn CentOS 7, use
yuminstead ofdnf. - Start and enable the service:
sudo systemctl start mariadb sudo systemctl enable mariadbenablemakes it start automatically on boot. - Check the status:
sudo systemctl status mariadbYou should see
active (running). - Secure the installation: Run
sudo mysql_secure_installation. This interactive script helps you set a root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privileges. AnswerYto all prompts for a secure default setup.
Post-Installation Configuration
After securing, you can log in with mysql -u root -p (the MariaDB client is named mysql). To create a database and user for an application, use SQL commands:
CREATE DATABASE myapp;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON myapp.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
The default configuration file is /etc/my.cnf or /etc/my.cnf.d/. You can adjust settings like max_connections or innodb_buffer_pool_size by adding lines under [mysqld] in a new file in /etc/my.cnf.d/ (e.g., custom.cnf). After changes, restart with sudo systemctl restart mariadb.
Common Problems and Fixes
- Can’t connect via socket: If you get
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock', the service is not running. Check withsudo systemctl start mariadb. - Root password not working: If you forgot it, stop the service (
sudo systemctl stop mariadb), start it withsudo mysqld_safe --skip-grant-tables &, log in withmysql -u root, and runFLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';then restart normally. - Port 3306 already in use: Another MySQL instance may be running. Check with
sudo ss -tlnp | grep 3306and stop the conflicting service. - SELinux blocking connections: If remote connections fail, SELinux may block them. Allow with
sudo setsebool -P httpd_can_network_connect_db 1for web apps, or adjust the port context if using a non-default port.
Choosing Between MariaDB and MySQL
On CentOS/Rocky, you have three main options:
- MariaDB from the distro repo – easiest, most compatible, and fully supported by the OS vendor. Recommended for most users.
- MySQL from Oracle’s official repo – if you need a specific MySQL version or features not in MariaDB (e.g., MySQL Enterprise plugins). Add the repo with
sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm(adjust for your version) thensudo dnf install mysql-server. Note: MySQL and MariaDB cannot coexist on the same system without conflict. - MariaDB from the official MariaDB repo – if you need a newer version than the distro’s. For example, to get MariaDB 10.11 on Rocky 9, use the MariaDB repository setup script from mariadb.org.
For most applications, the distro’s MariaDB is sufficient. If you need a specific feature or version, the official repos are the way to go.
Security and Maintenance
Always run mysql_secure_installation after install. Additional best practices:
- Use strong passwords and create separate users for each application with minimal privileges.
- Backup regularly using
mysqldumpor physical backups. For example,mysqldump -u root -p --all-databases > backup.sql. - Keep the system updated:
sudo dnf update. - Monitor logs in
/var/log/mariadb/(or/var/log/mysql/on some systems). - Consider using a firewall: allow port 3306 only from trusted IPs using
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="3306" accept'.
For production, you may also want to configure SSL/TLS for connections, but that is beyond the scope of a basic install.
Frequently Asked Questions
How do I uninstall MariaDB?
To remove MariaDB completely, stop the service, then run sudo dnf remove mariadb-server mariadb. To delete data files, remove /var/lib/mysql (be careful—this deletes all databases). Also remove config files in /etc/my.cnf.d/ if you want a clean slate.
Can I install MariaDB on CentOS 7?
Yes. CentOS 7 ships MariaDB 5.5 in its base repo. You can install it with sudo yum install mariadb-server. If you need a newer version, use the official MariaDB repository or the Software Collections (SCL) which offers MariaDB 10.x.
What is the default root password?
There is no default password. On a fresh install, root can log in via the unix_socket plugin, which allows only local system root user to log in without a password. After running mysql_secure_installation, you set a password and the socket plugin remains active, so sudo mysql still works as root.
How do I allow remote connections?
By default, MariaDB listens only on localhost. Edit /etc/my.cnf.d/mariadb-server.cnf and change bind-address to 0.0.0.0 (or a specific IP). Then create a user with a host of '%' or a specific IP, and ensure the firewall allows port 3306. Remember to restart the service.
What is the difference between MariaDB and MySQL commands?
For basic operations, they are identical. The client is called mysql, and SQL syntax is the same. Some advanced features differ: MariaDB uses Aria storage engine, has different system variables, and supports WITH clauses in more contexts. In practice, most applications work unchanged.
How do I upgrade MariaDB to a newer version?
If you installed from the distro repo, you can only get the distro’s version. To upgrade to a newer MariaDB release, add the official MariaDB repository (using mariadb_repo_setup script), then run sudo dnf upgrade mariadb-server. Always backup before upgrading. Note that major version upgrades may require running mysql_upgrade (or it runs automatically).
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix Text Cursor Turning White in Windows 11
- Force Quit Non-Responding Apps on Mac: 6 Ways
- Chromebook Not Charging? Fix It Fast
- iPhone Won’t Make Calls but Texts Work? Fixes
- Android to iPhone Hotspot: Connect & Fix Issues
- Fix Bluetooth Not Working on Discord Mobile