Home  >  Article  >  Database  >  How to set ip in mysql

How to set ip in mysql

PHPz
PHPzOriginal
2023-04-17 16:36:135023browse

MySQL is a software widely used in database management, whether it is used by businesses or individuals. In the process of using MySQL, we sometimes need to set its IP for remote access. Next, this article will introduce how to set the IP for MySQL.

1. Understand the necessity of MySQL IP settings

By default, MySQL will only allow local IP access, so we cannot connect remotely through other clients. Therefore, in order for other clients to be able to access MySQL, their IP settings need to be set.

2. Modify the MySQL configuration file

  1. Open the MySQL configuration file

First, we need to find the MySQL configuration file my.cnf, its location is It is slightly different under different operating systems:

Under Windows, it is generally stored in the data directory under the MySQL installation directory, such as C:\Program Files\mysql\data\my.cnf;

Under Linux, it is generally stored in the /etc directory, such as /etc/my.cnf.

  1. Modify the MySQL configuration file

Open the my.cnf file with a text editor and insert the following code in the [mysqld] tag:

[mysqld]
bind-address = 0.0.0.0

where , 0.0.0.0 means that any IP address is allowed to connect, or it can be set to a specific IP address, for example:

[mysqld]
bind-address = 192.168.1.100

means that only hosts with the IP address 192.168.1.100 are allowed to connect. After modification, save and exit.

3. Restart the MySQL service

After modifying the my.cnf file, we need to restart the MySQL service to make it take effect. Use the following command to restart the MySQL service:

Under Windows, you can use the "Service" manager, find MySQL, right-click and select "Restart";

Under Linux, you can use the following command to restart MySQL service:

service mysqld restart

4. Set up the MySQL user

Finally, we need to create a user who is allowed to access MySQL. Here we create a user with the user name "user" and the password "password" For example, the code is as follows:

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

Among them, % means that any host is allowed to connect, or it can be set to a specific IP address, for example:

GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.100' IDENTIFIED BY 'password' WITH GRANT OPTION;

means that only the IP address is allowed to be 192.168.1.100 host to connect.

In general, MySQL IP setting is a very important operation and needs to be taken seriously. Through the above steps, we can easily achieve remote access to MySQL, which provides great convenience for data management.

The above is the detailed content of How to set ip in mysql. 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