How to install MariaDB (MySQL) on Centos 7
Enjoying this content? Subscribe to the Channel!
Supercharge Your Server: How to Install MariaDB on CentOS 7 (Step-by-Step Guide)
Welcome back to Darren’s Tech Tutorials! Are you running CentOS 7 and ready to set up a robust, open-source relational database? You’ve come to the right place. MariaDB is a powerful drop-in replacement for MySQL, known for its speed, stability, and reliability.
In this quick, hands-on tutorial, we’re going to walk through the entire process, from installation to initial security setup and testing. Get ready to turn your CentOS server into a data powerhouse!
(P.S. Need a quick reference for common Linux commands? Don’t forget to grab your free Linux cheat sheet right here: http://eepurl.com/dkRNM9)
Prerequisites
Before we start installing MariaDB, ensure you have a working installation of CentOS 7 with sudo access. If you need help getting started with your CentOS setup, check out my full installation guide here: https://www.youtube.com/watch?v=qZXZepdUjRI
Once you’re logged into your server, let’s jump straight into the command line.
Step 1: Installing MariaDB Packages
We use the yum package manager in CentOS to handle the installation. We need two main components: the server package (the actual database) and the client package (tools to interact with the database).
Run the following two commands sequentially:
sudo yum install mariadb
sudo yum install mariadb-server
When prompted to confirm the installation and dependencies, type y and press Enter.
Step 2: Starting and Enabling the MariaDB Service
The packages are installed, but the database service isn’t running yet. We need to start the service immediately and then configure it to start automatically every time the server reboots.
2a. Start the Service
Use the systemctl command (or the legacy service command in this context) to bring MariaDB online:
sudo service mariadb start
(Note: If you encounter an error, ensure you typed mariadb correctly, avoiding the common typo mairadb!)
2b. Enable Automatic Startup
Now, let’s make sure MariaDB survives a reboot. We use chkconfig to ensure the service is persistent:
sudo chkconfig mariadb on
MariaDB is now installed, running, and configured to start with your system. Fantastic!
Step 3: Securing Your Database Installation
This is perhaps the single most important step. When MariaDB is first installed, it has insecure default settings (like no root password). We need to run the built-in security script to lock things down.
Execute the following command:
sudo mysql_secure_installation
This command will launch an interactive script that guides you through several critical security steps:
- Enter current password for root: Since this is a fresh install, hit Enter (there is no password yet).
- Set root password: Choose a strong, unique password. Do not skip this step!
- Remove anonymous users: Type
Y. This prevents anyone from logging into MariaDB without an account. - Disallow root login remotely: Type
Y. This is a vital security measure. You should only manage the database as root from the local server machine. - Remove test database and access to it: Type
Y. This cleans up unnecessary example data. - Reload privilege tables: Type
Y. This applies all your new security changes instantly.
Congratulations! Your MariaDB installation is now properly secured.
Step 4: Testing the Installation (Creating a Database)
Let’s confirm everything is working by logging in as the root user and creating our first database.
4a. Log in to MariaDB
Use the following command, which specifies logging in as the user root (-u root) and prompts you for the password (-p):
mysql -u root -p
Enter the strong root password you created in Step 3. You should now see the MariaDB command prompt (MariaDB [(none)]>).
4b. Create and Verify a Test Database
We will create a simple database named darren and then verify its existence. Remember, all SQL commands must end with a semicolon (;).
create database darren;
Now, check the list of available databases:
show databases;
You should see darren listed along with the standard system databases (information_schema, mysql, performance_schema).
Once confirmed, type exit; to return to your Linux command prompt.
Wrapping Up and Next Steps
You did it! In just four simple steps, you successfully downloaded, installed, secured, and tested MariaDB on your CentOS 7 server. You now have a powerful relational database ready to host your applications, websites, and projects.
Did this tutorial help you get set up? If so, please hit that Like button on the video and Subscribe to Darren’s Tech Tutorials for more clear, practical guides. Let me know in the comments what you’re planning to build with your new MariaDB setup!
Happy coding!