MySQL is an open-source database engine, suitable for small to large sites.
This article walks you through a basic installation of MySQL on a CentOS 7 server.
You need access to a Linux server, with sudoers or root privileges.
Update package information
Update your package information before you get started. For many of these Linux commands, you will receive multiple screens of output that this guide will shorten to ‘…‘, but here are the relevant messages to look out for:
#yum update ... Complete!
Install the MariaDB server package:
#sudo yum install mariadb-server ... Installed: mariadb-server.x86_64 1:5.5.64-1.el7 Dependency Installed: mariadb.x86_64 1:5.5.64-1.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 Complete!
In our example, CentOS installed MariaDB 5.5 by default. MariaDB is a MySQL drop-in replacement, with additional features.
To verify that MariaDB is installed and started on your system, run:
#sudo systemctl status mariadb.service ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: inactive (dead)
You can see that CentOS neither starts nor enables MariaDB for auto-start on reboot (vendor preset: disabled)
We’ll need to do both.
#sudo systemctl start mariadb.service #sudo systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
Now, check the status again:
#sudo systemctl status mariadb.service ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2019-12-13 19:23:15 UTC; 6min ago Main PID: 32025 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─32025 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─32187 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib6...
You should see Active: active (running) as in the example above.
Enter the MySQL shell to ensure that you have access. Then type exit to exit the shell.
#mysql MariaDB [(none)]> exit Bye
Now you can reach your MySQL from another remote host by using:
mysql -h host_name -u user -p
Run the Secure Installation Tool (Optional)
Finally, we recommend that you run MariaDB Server’s built-in secure installation tool. This will walk you through several steps intended to close some known vulnerabilities with the default installation, and will prompt you on which changes it should make at every step:
[root@drab-eagle-9 ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): ... Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
In this article, you learned how to install MariaDB on CentOS 7. The next steps should include configuring your firewall to properly allow only the needed traffic to your MariaDB server instance and configuring users with the correct permissions for your needs.