Home Database Mysql Tutorial Mysql教程之Windows 7/8下连接本地MySQL慢怎么办

Mysql教程之Windows 7/8下连接本地MySQL慢怎么办

Jun 07, 2016 pm 04:22 PM
mysql windows Tutorial local connect

最近本地调试网站的时候个别程序如phpcms一直出现这个问题,速度异常慢,偶尔发现下面的文章,才提醒了我,原来问题这样的。。。 最近在windows上开发应用的时候发现一个有趣的问题:我的本地程序连接本地mysql库居然要延迟1秒钟左右才能打开。 问题分析 考

   最近本地调试网站的时候个别程序如phpcms一直出现这个问题,速度异常慢,偶尔发现下面的文章,才提醒了我,原来问题这样的。。。

  最近在windows上开发应用的时候发现一个有趣的问题:我的本地程序连接本地mysql库居然要延迟1秒钟左右才能打开。

  问题分析

  考虑到可能是程序性能问题后,我使用了xdebug的性能日志功能输出程序运行日志后发现连接mysql的函数时间居然用掉了接近95%的执行时间。

  确认是mysql性能问题后,考虑是mysql的域名反查功能影响了速度,令我失望的是,在my.ini里面关闭域名反查后问题依旧存在。

  百思不得其解时我突发奇想将代码中的服务器的地址从localhost修改为了127.0.0.1,那个神奇的1秒钟延迟居然消失了。

  换成ip后居然就好了,难道是localhost存在啥蹊跷?打开cmd,输入ping localhost,ping输出的结果让我十分惊讶:

Mysql教程之Windows 7/8下连接本地MySQL慢怎么办 三联

  没错,,localhost 出来的是 ipv6 地址 ::1,那么这一秒延迟的原因也很容易理解了,使用localhost连接,程序解析出来的地址是ipv6地址::1,然后去尝试连接监听这个地址的mysql, 而显然的是mysql监听的是ipv4地址127.0.0.1, ipv6连不上超时后会再去连接ipv4地址127.0.0.1, 这就是这个1秒钟延迟出现的原因。

  打开windows的hosts文件,你会看到下面的注释

  # localhost name resolution is handled within DNS itself.

  # 127.0.0.1 localhost

  # ::1 localhost

  解决方法

  方案1. 使用127.0.0.1而不是localhost去连接mysql。

  方案2. 编辑hosts文件强制将127.0.0.1绑定在localhost。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

See all articles