Allow Remote Access to MariaDB Server on RHEL / CentOS
In this tutorial, I’m going to show how to allow remote access to MariaDB server on RHEL / CentOS. Let’s get started:
Table of Contents
Add New User
Login to your server and then login to MuSQL server:
mysql -u root -p
Now we’ll create a new user with all access:
GRANT ALL PRIVILEGES ON *.* TO 'remoteuser'@'%' IDENTIFIED BY 'new_password' WITH GRANT OPTION;
'%' means, user can login from any IP. If you want to give permission to access from a specific IP, you have to do like this:
GRANT ALL PRIVILEGES ON *.* TO 'remoteuser'@'192.168.52.43' IDENTIFIED BY 'new_password' WITH GRANT OPTION;
Just replace 192.168.52.43 with your IP.
You can flush the privileges too:
Open MySQL Port
If you enabled firewall on your server, then you need to open MySQL port. The default port is 3306. I’m opening port on firewalls:
# open port sudo firewall-cmd --permanent --add-port=3306/tcp # reload sudo firewall-cmd --reload
Connect to Database
From your server, you can check if remote connection works or not:
mysql -h SERVER_IP_OR_HOST -P 3306 -u remoteuser -p
If everything is okay, you’ll able to login & will see like this:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2676 Server version: 10.3.17-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
You can also config MariaDB. The config file’s path:
You can bind IP from the config file too. Just comment out this line and set your IP:
Visit Configuring MariaDB page to learn more about config.
If you failed to login, you can check SELinux status. To check SELinux:
If SELinux is enabled, you need to allow webserver to connect to remote database through SELinux:
That’s all. Thank you. ?
setsebool -P selinuxuser_mysql_connect_enabled 1
Preview may take a few seconds to load.
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Bold **double asterisks**
Three back ticks and then enter your code blocks here.
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
> type a greater than sign and start typing your quote.
You can add links by adding text inside of  and the link inside of (), like so:
To add a numbered list you can simply start with a number and a ., like so:
1. The first item in my list
For an unordered list, you can add a dash -, like so:
- The start of my list
You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of , and the image URL inside of (), like so:
To add a divider you can add three dashes or three asterisks:
--- or ***