Home > Database > Mysql Tutorial > mysql allows remote access

mysql allows remote access

黄舟
Release: 2017-02-15 10:53:24
Original
1319 people have browsed it


Mysql cannot be accessed remotely by default.

what! How can it be! Dongdong, which everyone praised so much, actually defaults to a stand-alone version. It's too toy.

Actually, this is only for the newly installed mysql. The newly installed mysql has only one account, which is the administrator root. It can only be accessed locally. There seems to be nothing wrong with it (but more cautious?).

So, how can we enable remote access, such as allowing other machines in the same LAN to access its database?

Assume that the newly installed MYSQL has the following initial account information:

+------+-----------+| user | host      |
+------+-----------+| root | 127.0.0.1 |
| root | ::1       || root | localhost |
+------+-----------+3 rows in set (0.14 sec)
Copy after login
Copy after login

After searching online, some experts said that the host can be changed to '%', so that it can be accessed by all machines. .

However, the situation I am encountering now is that there is a system developed by a third party, and we need to read data from its database. Its account defaults to the above, which can only be accessed locally. Do I need to modify its account? It seems that the change is very small and there should be no risk, but it still feels wrong.

However, basically all the tutorials on the Internet are based on the argument of changing the host to '%', and there are a lot of articles in the world.

I think the idea should be like this:

1. Create a user
2. Grant this user to allow remote access

After testing, it was successful. The steps are as follows:
1. Create user

create user 'test' identified by '123456'
Copy after login
Copy after login

The host of the user created in this way is '%'

If you want to limit access to a certain IP, you can use Jiangzi:

create user 'test'@'192.168.0.164' identified by '123456'
Copy after login
Copy after login

Okay, now we have created the user and allowed remote access.

2, but we still need to grant permissions

grant all on db1.* to test@'%';
Copy after login
Copy after login

Here, all the permissions of database db1 are given to test.

In this way, test can be used to access the mysql database.

3. Clear the password
The third-party system has its mysql account root and the password is empty. How to write it in the connection string? It turns out that there are three ways to write:

server=192.168.128.130; user id=test; password=;database=db1server=192.168.128.130; user id=test; password='';database=db1server=192.168.128.130; user id=test; database=db1
Copy after login
Copy after login

All of the above are fine. If you log in from the command line, you can do this:
mysql -u test (Enter)
to log in.

So how to clear the password? Can Jiang Zi:

set password for test@'%'=password('');
Copy after login
Copy after login

sighs the excellence of mysql. It seems that its account is actually determined by account name + host, which is equivalent to a composite primary key. This idea is very novel. Very practical too.

Mysql cannot be accessed remotely by default.

what! How can it be! Dongdong, which everyone praised so much, actually defaults to a stand-alone version. It's too toy.

Actually, this is only for the newly installed mysql. The newly installed mysql has only one account, which is the administrator root. It can only be accessed locally. There seems to be nothing wrong with it (but more cautious?).

So, how can we enable remote access, such as allowing other machines in the same LAN to access its database?

Assume that the newly installed MYSQL has the following initial account information:

+------+-----------+| user | host      |
+------+-----------+| root | 127.0.0.1 |
| root | ::1       || root | localhost |
+------+-----------+3 rows in set (0.14 sec)
Copy after login
Copy after login

After searching online, some experts said that the host can be changed to '%', so that it can be accessed by all machines. .

However, the situation I am encountering now is that there is a system developed by a third party, and we need to read data from its database. Its account defaults to the above, which can only be accessed locally. Do I need to modify its account? It seems that the change is very small and there should be no risk, but it still feels wrong.

However, basically all the tutorials on the Internet are based on the argument of changing the host to '%', and there are a lot of articles in the world.

I think the idea should be like this:

1. Create a user
2. Grant this user to allow remote access

After testing, it was successful. The steps are as follows:
1. Create user

create user 'test' identified by '123456'
Copy after login
Copy after login

The host of the user created in this way is '%'

If you want to limit access to a certain IP, you can use Jiangzi:

create user 'test'@'192.168.0.164' identified by '123456'
Copy after login
Copy after login

Okay, now we have created the user and allowed remote access.

2, but we still need to grant permissions

grant all on db1.* to test@'%';
Copy after login
Copy after login

Here, all the permissions of the database db1 are given to test.

In this way, test can be used to access the mysql database.

3. Clear the password
The third-party system has its mysql account root and the password is empty. How to write it in the connection string? It turns out that there are three ways to write:

server=192.168.128.130; user id=test; password=;database=db1server=192.168.128.130; user id=test; password='';database=db1server=192.168.128.130; user id=test; database=db1
Copy after login
Copy after login

All of the above are fine. If you log in from the command line, you can do this:
mysql -u test (Enter)
to log in.

So how to clear the password? Can Jiang Zi:

set password for test@'%'=password('');
Copy after login
Copy after login

sighs the excellence of mysql. It seems that its account is actually determined by account name + host, which is equivalent to a composite primary key. This idea is very novel. Very practical too.

The above is the content that mysql allows remote access. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template