Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of mysql authorization method for remote connection

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Today, there is a mysql database on the server, remote access, do not want to publish the root account, so, created a demo account, allowing the demo account to access the shandong library in the mysql database anywhere.

Option 1:

Run on the machine where mysql is installed:

1: create a user user

The copy code is as follows:

CREATE USER demo IDENTIFIED BY "123456"

2 、

The copy code is as follows:

Mysql > GRANT ALL PRIVILEGES ON shandong.* TO 'demo'@'%'WITH GRANT OPTION

/ / give any host permission to access data, or you can do the following

GRANT ALL PRIVILEGES ON shandong.* TO 'demo'@'%'IDENTIFIED BY' 123456 'WITH GRANT OPTION

3 、

The copy code is as follows:

Mysql > FLUSH PRIVILEGES

/ / the modification takes effect

4 、

The copy code is as follows:

Mysql > EXIT

/ / log out of the MySQL server so that you can log in as demo on any other host

Quote

In addition, when using the client to connect to the mysql, it is found that the connection cannot be made, and it seems that the user needs to be reauthorized. Do the following:

[root@cicro108 mysql] # bin/mysql-uroot-p-h 127.0.0.1-A cws3

Enter password:

Welcome to the MySQL monitor. Commands end with or / g.

Your MySQL connection id is 1863 to server version: 4.1.20-standard

Type 'help;' or' / h' for help. Type'/ c'to clear the buffer.

Mysql > grant ALL PRIVILEGES ON *. * to root@ "%" identified by "mysql"

Query OK, 0 rows affected (0.17 sec)

It is found that after changing the permissions in this way, the remote still cannot connect, but you can use the following actions.

Mysql > grant ALL PRIVILEGES ON *. * to root@ "%" identified by "mysql" WITH GRANT OPTION

Query OK, 0 rows affected (0.17 sec)

At this point, root can be connected remotely, but other non-root users can also connect remotely here.

Option 2:

MySQL 1130 error Resolution:

This error occurs when connecting to MySQL through MySQL-Front or MySQL administrator

ERROR 1130: Host *. * is not allowed to connect to this MySQL server

Indicates that the connected user account does not have the permission to connect remotely and can only log in on the local machine (localhost).

You need to change the host entry in the user table in the MySQL database

Rename localhost%

Specific steps: log in to MySQL

First of all, use MySQL

An error occurred when update in the way provided by others.

MySQL > update user set host='%' where user = 'root'

ERROR 1062 (23000): Duplicate entry'%-root' for key 'PRIMARY'

Then check the host information of the following database as follows:

MySQL > select host from user where user = 'root'

+-- +

| | host |

+-- +

| |% |

| | 127.0.0.1 | |

| | localhost.localdomain |

+-- +

3 rows in set (0.00 sec)

Host already has the% value, so run the command directly:

The copy code is as follows:

MySQL > flush privileges

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report