Install MariaDB 10.1 on Fedora 25/24, CentOS/RHEL 7.3/6.8/5.11
MariaDB is a binary drop in replacement for MySQL database server. This means that for most cases, you can just uninstall MySQL and install MariaDB and you are good to go.
Why MariaDB?
- MariaDB is totally open source version of MySQL
- It works just like MySQL and is compatible with MySQL setups
- Fedora and Red Hat/CentOS is moving to use MariaDB from Fedora 19/RHEL 7/CentOS 7 versions
This is guide, howto install or upgrade MariaDB 10.1.20 [stable] (10.0.28 [stable] or 10.2.2 [beta] or 5.5.53 [stable]) on Fedora 25/24/23, CentOS 7.3/6.8/5.11 and Red Hat (RHEL) 7.3/6.8/5.11. Installing MariaDB is almost same process than install MySQL.
Note: If you are moving from MySQL, then make sure that you backup (dump and copy) your database and configs. And if upgrading from earlier versions, then remember run mysql_upgrade command. And if you uninstall MySQL, then remember restore /etc/my.cnf after installation, like:
Bash
mv -vi /etc/my.cnf.rpmsave /etc/my.cnf
Install MariaDB/MariaDB-server 10.1.20/10.0.28/10.2.2/5.5.53 on Fedora 25/24/23, CentOS 7.3/6.8/5.11, Red Hat (RHEL) 7.3/6.8/5.11
1. Change root user
Bash
su -
## OR ##
sudo -i
2. Install MariaDB repository
Following commands are just shortcut to install original MariaDB YUM repos, alternatively you can use MariaDB repository configuration tool.
Fedora 25/24/23
Note: currently Fedora 25/24/23 users can install MariaDB 10.1 and not additional repos needed or alternatively use MariaDB repos to install some other version.
Bash
## Fedora 25/24/23 MariaDB 10.1 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/fedora/$(rpm -E %fedora)/$(uname -i)/10_1
## OR ##
## Fedora 25/24/23 MariaDB 10.2 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/fedora/$(rpm -E %fedora)/$(uname -i)/10_2
CentOS 7/6/5
Bash
## CentOS 7/6/5 MariaDB 10.1 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/centos/$(rpm -E %centos)/$(uname -i)/10_1
## OR ##
## CentOS 7/6/5 MariaDB 10.2 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/centos/$(rpm -E %centos)/$(uname -i)/10_2
## OR ##
## CentOS 7/6/5 MariaDB 10.0 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/centos/$(rpm -E %centos)/$(uname -i)/10
## OR ##
## CentOS 7/6/5 MariaDB 5.5 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/centos/$(rpm -E %centos)/$(uname -i)/5
Red Hat (RHEL) 7/6/5
Bash
## Red Hat (RHEL) 7/6/5 MariaDB 10.1 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/rhel/$(rpm -E %rhel)/$(uname -i)/10_1
## OR ##
## Red Hat (RHEL) 7/6/5 MariaDB 10.2 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/rhel/$(rpm -E %rhel)/$(uname -i)/10_2
## OR ##
## CentOS 7/6/5 MariaDB 10.0 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/centos/$(rpm -E %centos)/$(uname -i)/10
## OR ##
## Red Hat (RHEL) 7/6/5 MariaDB 5.5 ##
wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/rhel/$(rpm -E %rhel)/$(uname -i)/5
3. Update or Install MariaDB 10.1/10.0
Fedora 25/24/23 (own packages)
Bash
dnf install mariadb mariadb-server
CentOS/Red Hat (RHEL) 7.3/6.8/5.11 (and Fedora 25/24/23 using MariaDB repos)
Bash
yum install MariaDB MariaDB-server
4. Start MariaDB server and autostart MariaDB on boot
Fedora 25/24/23 and CentOS/RHEL 7.3
Bash
systemctl start mariadb.service ## use restart after update
systemctl enable mariadb.service
CentOS 6.8/5.11 and Red Hat (RHEL) 6.8/5.11
Bash
service mysql start ## use restart after update
## OR ##
/etc/init.d/mysql start ## use restart after update
chkconfig --levels 235 mysql on
5. MariaDB (MySQL) Secure Installation
- Set (Change) root password
- Remove anonymous users
- Disallow root login remotely
- Remove test database and access to it
- Reload privilege tables
Start MariaDB (MySQL) Secure Installation with following command
Bash
/usr/bin/mysql_secure_installation
Output:
Bash
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):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from \'localhost\'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named \'test\' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
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!
Note: If you don’t want some reason, do a “MySQL Secure Installation” then at least it’s very important to change the root user’s password
Bash
mysqladmin -u root password [your_password_here]
## Example ##
mysqladmin -u root password myownsecrectpass
6. Connect to MySQL database (localhost) with password
Bash
mysql -u root -p
## OR ##
mysql -h localhost -u root -p
7. Create Database, Create MySQL User and Enable Remote Connections to MySQL Database
This example uses following parameters:
- DB_NAME = webdb
- USER_NAME = webdb_user
- REMOTE_IP = 10.0.15.25
- PASSWORD = password123
- PERMISSIONS = ALL
SQL
## CREATE DATABASE ##
MariaDB [(none)]> CREATE DATABASE webdb;
## CREATE USER ##
MariaDB [(none)]> CREATE USER 'webdb_user'@'10.0.15.25' IDENTIFIED BY 'password123';
## GRANT PERMISSIONS ##
MariaDB [(none)]> GRANT ALL ON webdb.* TO 'webdb_user'@'10.0.15.25';
## FLUSH PRIVILEGES, Tell the server to reload the grant tables ##
MariaDB [(none)]> FLUSH PRIVILEGES;
Enable Remote Connection to MariaDB Server –> Open MySQL Port (3306) on Iptables Firewall (as root user again)
1. CentOS/Red Hat (RHEL) 6.8/5.11
1.1 Edit /etc/sysconfig/iptables file:
Bash
nano -w /etc/sysconfig/iptables
1.2 Add following INPUT rule:
Bash
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
1.3 Restart Iptables Firewall:
Bash
service iptables restart
## OR ##
/etc/init.d/iptables restart
2. Fedora 25/24/23 and CentOS/Red Hat (RHEL) 7.3
2.1 List Your Active Firewalld Zones
Bash
firewall-cmd --get-active-zones
Example output:
public interfaces: wlp1s0
2.2 Add New Rule to Firewalld
You might have active zone like public, FedoraWorkstation, FedoraServer.
Bash
firewall-cmd --permanent --zone=public --add-service=mysql
## OR ##
firewall-cmd --permanent --zone=public --add --port=3306/tcp
2.3 Restart firewalld.service
Bash
systemctl restart firewalld.service
3. Test remote connection
Bash
mysql -h 10.0.15.25 -u myusername -p
Comments
Post a Comment