Tutorial on how to remotely connect to MySQL database under Linux system

Tutorial on how to remotely connect to MySQL database under Linux system

Preface

I recently encountered this requirement at work, and it took me more than an hour to get the remote connection established. A local computer and a cloud server, both are Linux systems. Let's take a look at the detailed introduction:

step

1. Enable remote access on the server

First enter the mysql database, and then enter the following two commands:

grant all privileges on *.* to 'root'@'%' identified by 'password';
flush privileges;

The first * is the database, which can be changed to the name of the database that is allowed to be accessed

The second is the database table name, which means that access to any table is allowed.

root represents the user name used for remote login, which can be customized

% means that any IP is allowed to log in. If you want to specify a specific IP, you can replace it with %.

Password represents the password used for remote login, which can be customized

flush privileges; This makes the privileges take effect immediately

2. Modify the my.cnf configuration file

This is the mysql configuration file. If you can't find it, you can enter find /* -name my.cnf to find it.

Edit the file using vim, find the line bind-address = 127.0.0.1 , add a # in front of it to comment it out, save the file and exit.

3. Restart the service

service mysql restart

4. Remote connection locally

Type in the terminal:

mysql -h server ip address -P 3306 -u root -p

Then enter your password.

root is the username set in point 1, and the password is also the password set in point 1

Some details

I found a lot of articles online, saying that I need to open port 3306 to connect, but I still can't connect after I opened it. Later, I found some articles saying that I need to change my.cnf, which is the second point above. After changing it, restart the server.

I just tried it on another server. The port was not configured. After following the above three steps, I was able to connect quickly.

So the second point is very important. Basically everyone will configure that file when installing MySQL because the character set needs to be configured. So the file must exist. Just use the find command to find it.

Summarize

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • How to enable remote connection to MySQL database
  • Solution to MySQL remote connection loss problem (Lost connection to MySQL server)
  • Detailed explanation of remote connection to MySQL authorization method
  • How to configure mysql to allow remote connections
  • How to solve the problem of slow remote connection to MySQL (mysql_connect opens the connection slowly)
  • Solution to MySQL remote connection failure
  • mysql remote connection database method collection
  • A solution to MYSQL not being able to connect remotely (s not allowed to connect to this MySQL server)
  • How to solve the problem that MySQL cannot be connected remotely
  • MySql8 actual record of setting up remote connection

<<:  Vue routing to implement login interception

>>:  Linux kernel device driver address mapping notes

Recommend

uni-app implements NFC reading function

This article shares the specific code of uni-app ...

Details on using regular expressions in MySQL

Table of contents 1. Introduction 2. Prepare a pr...

Detailed explanation of mysql integrity constraints example

This article describes the MySQL integrity constr...

Implementation of modifying configuration files in Docker container

1. Enter the container docker run [option] image ...

MySQL table return causes index invalidation case explanation

Introduction When the MySQL InnoDB engine queries...

Simple implementation method of two-way data binding in js project

Table of contents Preface Publish-Subscriber Patt...

Detailed explanation of MySQL alter ignore syntax

When I was at work today, the business side asked...

Implementation code of using select to select elements in Vue+Openlayer

Effect picture: Implementation code: <template...

Nginx merges request connections and speeds up website access examples

Preface As one of the best web servers in the wor...

Detailed explanation of MySQL batch SQL insert performance optimization

For some systems with large amounts of data, the ...

How to maintain MySQL indexes and data tables

Table of contents Find and fix table conflicts Up...

Comparison of several examples of insertion efficiency in Mysql

Preface Recently, due to work needs, I need to in...

MySQL 5.5.27 installation graphic tutorial

1. Installation of MYSQL 1. Open the downloaded M...

HTML web page creation tutorial Use iframe tags carefully

Using iframes can easily call pages from other we...