Allow Remote Access to MariaDB Server on RHEL / CentOS

Allow Remote Access to MariaDB Server on RHEL / CentOS

 Allow Remote Access to MariaDB Server on RHEL / CentOS

In this tutorial, I’m going to show how to allow remote access to the MariaDB server on RHEL / CentOS. Let’s get started:


Table of Contents

  1. Add New User
  2. Open MySQL Port
  3. Connect to Database
  4. Configure MariaDB
  5. Note

Add New User

Login to your server and then log in to the MySQL 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;

Hear, '%' means, the user can log in from any IP. If you want to give permission to access from a specific IP, you have to do 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:

FLUSH PRIVILEGES;

Open MySQL Port

If you enabled a firewall on your server, then you need to open the 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)]>

Configure MariaDB

You can also config MariaDB. The config file’s path:

/etc/my.cnf.d/mariadb-server.cnf

You can bind IP from the config file too. Just comment out this line and set your IP:

bind-address=0.0.0.0

Visit Configuring MariaDB page to learn more about config.

Note

If you failed to log in, you can check SELinux status. To check SELinux:

sestatus

If SELinux is enabled, you need to allow the webserver to connect to a remote database through SELinux:

setsebool -P selinuxuser_mysql_connect_enabled 1

 That’s all. Thank you. ?

StarCode Kh

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

Previous Post Next Post
close