
How to install latest MySQL (MariaDB) on a CentOS 7 server
For CentOS, it is highly recommended to install from a repository using yum.
Start by adding the MariaDB YUM repository file MariaDB.repo
nano /etc/yum.repos.d/MariaDB.repo
An example MariaDB.repo file for CentOS 7 is:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
With the repo file in place you can now install MariaDB like so:
sudo yum install MariaDB-server MariaDB-client
After the installation completes, start MariaDB with:
sudo systemctl start mariadb
Now that our MySQL database is running, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running:
sudo mysql_secure_installation
MariaDB (MySQL) Secure Installation includes:
- Set (Change) root password
- Remove anonymous users
- Disallow root login remotely
- Remove test database and access to it
- Reload privilege tables
The last thing you will want to do is enable MariaDB to start on boot. Use the following command to do so:
sudo systemctl enable mariadb
Some other extra commands
To check MySQL version
mysql -V
To check the status of MySQL
sudo systemctl status mariadb
Connect to MySQL database (localhost) with password
mysql -u root -p