Solution to the failure of remote connection to MySQL database in Linux configuration

Solution to the failure of remote connection to MySQL database in Linux configuration

Today I have a question about configuring MySQL database under Linux for remote access. Baidu has a lot of information on this, but the methods are the same. I have tried them all but failed to solve them. I will record them here.

Step 1: Find bind-address = 127.0.0.1 in /etc/mysql/my.cnf

Add a "#" before this line to comment it out, or change it to: bind-address = 0.0.0.0

Allow any IP address to access; or specify the IP address that you need to access remotely.

Then restart mysql: sudo /etc/init.d/mysql restart

Step 2: Authorize users to connect remotely

grant all privileges on *.* to root@"%" identified by "password" with grant option;
 flush privileges;

The first line of command is explained as follows: *.*: the first * represents the database name; the second * represents the table name. This means that all tables in all databases are authorized to the user. If you only want to authorize a certain database or a table under a database, replace * with the database name and table you need. root: Grant the root account. “%”: Indicates that the authorized user IP can be specified, which means that any IP address can access the MySQL database. "password": the password corresponding to the assigned account. Replace the password with your root account password.

The second line of command refreshes the permission information, allowing the permissions we set to take effect immediately.

But in the end, it still cannot be accessed. At this time, it may be a problem with the firewall and MySQL port 3306.

I used the command netstar -a to query all ports but did not see port 3306. I used the command nerstat -an|grep 3306 but nothing was displayed. This means that port 3306 does not exist.

Log in to the Alibaba Cloud console, add a new rule in the cloud service security group, clone a rule and change the port number to 3306 of MySQL. The remote connection still fails again.

At this time, the console needs to restart the system to make the newly added rules take effect. After the restart, the connection still fails. At this time, the local navicat software connection returns an access denied error instead of the previous unable to connect error.

At this time, execute the second step above to authorize the user command again, and after restarting Apache MySQL, the connection is finally successful.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Tutorial on installing JDK Tomcat MySQL on Linux (remote access using Mac)
  • How to enable MySQL remote connection in Linux server
  • How to remotely connect to MySQL database under Linux
  • Tutorial on how to remotely connect to MySQL database under Linux system
  • Linux platform mysql enable remote login
  • Enable remote access rights for MySQL under Linux and open port 3306 in the firewall
  • Solution to the problem that the MySQL database on the Linux side of the virtual machine cannot be accessed remotely
  • How to install and set up Linux mysql command to allow remote connection
  • MySQL 5.7 deployment and remote access configuration under Linux

<<:  Use Javascript to develop sliding-nav navigation plug-in with sliding bar effect

>>:  How to use squid to build a proxy server for http and https

Recommend

MySQL 5.7.15 version installation and configuration method graphic tutorial

This article shares with you a detailed tutorial ...

Analysis and solution of a MySQL slow log monitoring false alarm problem

Previously, for various reasons, some alarms were...

js native waterfall flow plug-in production

This article shares the specific code of the js n...

JavaScript flow control (loop)

Table of contents 1. for loop 2. Double for loop ...

React uses emotion to write CSS code

Table of contents Introduction: Installation of e...

Linux nohup to run programs in the background and view them (nohup and &)

1. Background execution Generally, programs on Li...

20 JavaScript tips to help you improve development efficiency

Table of contents 1. Declare and initialize array...

How to create a basic image of the Python runtime environment using Docker

1. Preparation 1.1 Download the Python installati...

How to configure MySQL scheduled tasks (EVENT events) in detail

Table of contents 1. What is an event? 2. Enable ...

CSS3+Bezier curve to achieve scalable input search box effect

Without further ado, here are the renderings. The...

Detailed installation process of MySQL 8.0 Windows zip package version

The installation process of MySQL 8.0 Windows zip...

JavaScript implements simple scroll window

This article example shares the specific code of ...

43 Web Design Mistakes Web Designers Should Watch Out For

This is an article about website usability. The a...