Home Linux ServerWeb Server How to activate Remote SQL Server on Linux

How to activate Remote SQL Server on Linux

by Thạch Phạm
Published: Last Updated on
A+A-
Reset

How to activate Remote SQL Server on Linux with 2 methods!

I. Introduction

Welcome back to the AZDIGI documentation channel. In today’s article, AZDIGI will guide you on how to activate the remote SQL feature on the Linux system for any user or all databases under the root user.

In some control panels such as cPanel, this remote feature is already available, and you only need to configure it to enable remote access. However, for servers installed manually or some scripts, you need to assign permissions to these remote users. To do this, please refer to this tutorial.

II. Implementation guide

First, open the my.cnf file. Then, find the value of bind-address = 127.0.0.1, which means the server will only look for local connections. You need to change this value with your fixed IP address or use *, ::, or 0.0.0.0 to allow all connections.”

vi /etc/my.cnf
CleanShot 2022 05 18 at

Next, to proceed, you need to identify the user that needs to activate remote access. You must also be able to access the database under the root privilege by using the command mysql -u root -p and logging in with the MySQL root password. This information is set up during the installation of MySQL/MariaDB.

Activate Remote SQL Server on Linux

1. Activate remote access for any database

To enable Remote SQL for a user, you use the following command:

Step 1: Access the database

First, you access the database as root to enable remote sql for the specified user.

AZDIGI Tutorial
mysql -u root -p
    

As shown above, I have many databases and I will enable remote for the database named database1 as follows:

Step 2: Remote SQL

To enable for a certain database, you use the following command:

AZDIGI Tutorial
mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO 'database1'@'%' IDENTIFIED BY 'Mat_Khau_User_Database' WITH GRANT OPTION;
FLUSH PRIVILEGES;
    

And you need to change the following:

  • database1: replace with your database name
  • Mat_Khau_User_Database: Enter your Database user password
  • %: If you allow all IP addresses to access remotely, use the % sign. If you only allow one IP address, replace it with your IP address.

After completion, exit and restart the mysql/mariadb service. After completion, exit and restart the mysql/mariadb service. Here, I’m using MariaDB, so I will restart it using the command systemctl restart mariadb

For example:

Activate Remote SQL Server on Linux

Check SQL connection

Here, I’m using the Navicat software to connect. In addition, you can use other software such as Workbench or PHP functions.

Below is an actual image of the connection and the information, including:

  • Connection Name: Set any name
  • Host: Enter the server’s IP
  • Port: 3306 (default)
  • User Name: Enter your database user
  • Edit Password: Enter Database User Password
Activate Remote SQL Server on Linux

After importing, click Test Connection to check. If the screen shows the message Connection Successful as shown below, it is successful.

Activate Remote SQL Server on Linux

And this is the successful connection message when activating remote sql.

Activate Remote SQL Server on Linux

2. Active for the entire Database

If your server has multiple database accounts, and you want to activate remote access for all of them using the root user to remote and execute all databases, you can follow these steps.

Step 1: Access the database

Use the command mysql -u root -p, then enter the mysql root password to log in.

AZDIGI Tutorial
mysql -u root -p
    

Step 2: Activate remote SQL

Use the following command to activate remote MySQL for the root user:

AZDIGI Tutorial
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mat_khau_root_mysql' WITH GRANT OPTION;
FLUSH PRIVILEGES;
    

In there:

  • root is the root user used for remote access.
  • %: If you allow all IP addresses to access remotely, use the % sign. If you only allow one IP address, replace it with your IP address.
  • mat_khau_root_mysql: You enter the MySQL root password.
Screenshot 2021 01 21 at 09.35.32

Restart the MySQL/MariaDB service

After completion, exit and restart the mysql/mariadb service. After completion, exit and restart the mysql/mariadb service. Here, I’m using MariaDB, so I will restart it using the command systemctl restart mariadb

AZDIGI Tutorial
systemctl restart mariadb
    

Check SQL connection

Here, I’m using the Navicat software to connect. In addition, you can use other software such as Workbench or PHP functions.

Screenshot 2021 01 21 at 10.43.20 1

Below is an actual image of the connection and the information, including:

  • Connection Name: Set any name
  • Host: Enter the server’s IP
  • Port: 3306 (default)
  • User Name: Enter root
  • Edit Password: Enter the root mysql password

GIF image demonstrating the demo

Screenshot 2021 01 21 at 09.46.08

Note: If you cannot access PORT 3306, you need to open IN/OUT Port 3306 on the firewall to make it work.

Screenshot 2021 01 21 at 10.45.01

III. Summary

So AZDIGI has completed the steps to activate Remote SQL Server on Linux. Wishing you success! See more useful articles about Linux VPS at the following link:

If you need assistance, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign