Home>Article>Database> Detailed explanation of MySQL remote connection method in Linux server

Detailed explanation of MySQL remote connection method in Linux server

小云云
小云云 Original
2018-01-17 09:19:01 1971browse

The msyql database is installed on the Linux server. It can be accessed when accessed locally, but when I want to access it remotely, I cannot access it. After querying the information, I found that by default, MySQL under Linux only has local access after the installation is completed. permissions, there is no remote access permission. You need to set access permissions for the specified user to remotely access the database.

Preface

Learn MySQL to reorganize previous non-MK records

Description

If it is not enabled, an error will be reported when connecting to the database: 2003-can't connect to MYSQL

Method/step

•First step

Connect to the Linux system remotely and ensure that the MySQL database has been installed on the Linux system. Log in to the database.

mysql -u$user -p $pwd

##•Step 2

Create a user for remote connection


GRANT ALL PRIVILEGES ON *.* TO '$username'@'%' IDENTIFIED BY '$password' WITH GRANT OPTION;

$username represents the user name, % means that all computers can connect, you can also set an IP address to run the connection, $password means the password


•Step 3

Execute flush privileges; command immediately Valid


FLUSH PRIVILEGES;

•Step 4

Query the user of the database


SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

• Step 5

Then open

vim /etc/mysql/my.cnf

set bind-address = 127.0.0.1


Set to

bind-address = 0.0.0.0(device address)

Restart


/etc/init.d/mysql restart

•View MYsql global port (default is 3306)

#View port number

show global variables like 'port';

The configuration has been completed so far


Related recommendations:

Examples to explain how to modify mysql to enable remote connections

Example detailed explanation of the steps to configure MySQL remote connection under Alibaba Cloud

The reason why the mysql database cannot be connected remotely under Centos7 and the detailed solution

The above is the detailed content of Detailed explanation of MySQL remote connection method in Linux server. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn