After MySQL is installed, only the following hosts are recognized: localhost, 127.0.0.1, and mysqllocalhost.

Source: Internet
Author: User

After MySQL is installed, only the following hosts are recognized: localhost, 127.0.0.1, and mysqllocalhost.

The only hosts recognized after MySQL is installed are localhost and 127.0.0.1. If you want to allow the IP address on your machine to log on normally, there are two methods:
First, authorize your IP address 172.16.1.10
Grant privileges on dbname. * to "user" @ "172.16.1.10" identified by "password ";


If you only use it, you can write it like this.
Grant all on *. * to "user" @ "172.16.1.10" identified by "password ";


For more information about grant, see the mysql user manual.

Mysql> use mysql;
Database changed

Mysql> desc user; check the number of fields
Mysql> insert into user values (val1, val2 ,....);

 

The second is to set the root user to be able to log on remotely, that is, to log on from any machine.
Mysql> use mysql;
Database changed
Mysql> update user set host = "%" where user = "root ";


Mysql> use mysql
Grant all on *. * to "root" @ "172.30.41.72" identified by "x0000304 ";
Restart mysql server

 

Method 3: run the following command directly in the mysql database management background:
Use mysql;
Grant all on *. * to "root" @ "172.30.41.95" identified by "x0000304 ";


Php connection to mysql: I cannot connect to the database with localhost. I can connect to mysql with 127001, But I can connect to mysql with tools. Why?

Check the hosts file in system32 to see if localhost is directed to another address.
By default, there is only one such message.
Localhost 127.0.0.1

Localhost is different from the web page opened during the 127001 test.

What is opened ??

Is it another URL on your host?
You are running the command CMD.
Ping localhost

Check the IP address.

Localhost indicates local
Generally, the IP address is 127.0.0.1.
That is to say, I ping 127.0.0.1 = ping localhost

127.0.0.1 represents the loop address of your machine. Whether connected or not, 127.0.0.1 and 127 are reserved segments.

Relationship between localhost and 127.0.0.1:
Localhost can be regarded as the host name, 127 -- it can be regarded as the host ip address, which was previously mapped from a host name to an ip address in the middle!
If you connect to the database in mysql, use localhost instead of 127.0.0.1. In mysql, the user logon location is limited. For details, see the user table in mysql database (database Name Is mysql). The ip address and domain name are different, mysql does not automatically convert the ip address to the domain name when matching. You authorize a user to access from this ip address. It does not mean authorizing the user to access from this ip address.
1. Use TCP/IP to connect to mysql-h 127.0.0.1,
Mysql server considers the connection from 127.0.0.1 or "localhost. localdomain ".
2. For mysql-h localhost, Unix socket is used instead of TCP/IP connection;
Mysql server considers the client as from "localhost ".

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.