In some programs, it is often necessary to connect to a local database to test the program. Sometimes the mysql database cannot be connected using localhost, but the link can be successful using 127.0.0.1. For the convenience of testing, the computer needs to be properly configured. Configure so that localhost can also successfully connect to the mysql database.
1. First use Navicat for MySQL to create a database locally.
## 2. Create a PHP in dreamweaver Formatted web pages to facilitate link testing.
4. If the third step occurs, you need to modify C :\Windows\System32\drivers\etc directory hosts file.
##5. Open hosts with notepad,
Find the line 127.0.0.1 localhost, delete the "#" in this line, and save it.
If there is no such line, add it manually.
##6. After saving, before using again Web page test,
At this time, you can connect the local mysql database through localhost
The above is the detailed content of How to solve the problem that localhost cannot connect to the local mysql database. For more information, please follow other related articles on the PHP Chinese website!