连接速度很慢(1 秒)
我在 Windows 7 上运行 MySQL 5.6(64 位).我在 32 位 Windows 7 上测试最近从 MySQL 5.0 升级的数据库.(我还复制了 my.ini,做了一些更改)
我发现建立连接需要很长时间(大约 1 秒).例如,我创建了一个非常简单的 SQL 脚本:
选择1作为n;
然后我在一个批处理文件中运行了 10 次,花了 10 秒才完成:
mysql -h localhost -u root -D myschema 0<脚本文件
(是的,这里没有密码,这是一个只监听127.0.0.1的测试DB)
有人知道为什么这么慢吗?(见下面的my.ini)
[客户]端口=3306[mysql]默认字符集=latin1[mysqld]端口=3306绑定地址=127.0.0.1basedir="C:/Program Files/MySQL/mysql-5.6.10-winx64/"数据目录=C:/数据字符集服务器=latin1默认存储引擎=myisamsql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"最大连接数=100query_cache_size=0table_open_cache=256tmp_table_size=18Mthread_cache_size=8myisam_max_sort_file_size=100Gmyisam_sort_buffer_size=35Mkey_buffer_size=25Mread_buffer_size=64Kread_rnd_buffer_size=256Ksort_buffer_size=256Kinnodb_additional_mem_pool_size=2Minnodb_flush_log_at_trx_commit=1innodb_log_buffer_size=1Minnodb_buffer_pool_size=47Minnodb_log_file_size=24Minnodb_thread_concurrency=8log-bin=c:/data/mysql/binarylogmax_binlog_size=1024M启用命名管道慢查询日志=expire_logs_days=90
解决方案 Doh!看起来这是一个骗局.见:
为什么连接到 MySQL 服务器这么慢?>
https://serverfault.com/questions/408550/connecting-to-mysql-from-php-is-extremely-slow
我在 64 位机器上启用了 IPv6,而不是 32 位机器上.当我使用以下备用字符串连接时,事情会快得多:
mysql -h 127.0.0.1 -u root -D myschema 0<脚本文件
仍然不确定为什么会发生这种情况,但至少有一个解决方法!唉,可怜的 localhost
我很了解他.
my.ini 的以下更改允许在脚本和连接字符串中使用 localhost
:
绑定地址=::1
注意:绑定到 ::ffff:127.0.0.1
或 localhost
似乎没有帮助.我读到将 IPv6 和 IPv4 地址绑定到 MySQL 服务器以便所有 3 个连接字符串都可以工作(例如 -h ::1
、-h 127.0.0.1
、-h 本地主机
).但是,我一次只能让其中一两个客户端字符串起作用.
绑定方式如下:
绑定地址=*
完全解决了这个问题,IPv4 和 IPv6 客户端都可以连接.唯一的缺点是现在允许远程连接.我还没有找到一种在 localhost
限制下使用 TCP 并同时绑定到 127.0.0.1
和 ::1的方法代码>.
I'm running MySQL 5.6 (64-bit) on Windows 7. I'm testing a DB recently upgraded from MySQL 5.0 on 32-bit Windows 7. (I also copied my.ini, with a few changes)
I'm finding that it takes a very long time to establish a connection (on the order of 1 second). As an example, I created a very simple SQL script:
select 1 as n;
I then ran this in a batch file 10 times which took 10 seconds to complete:
mysql -h localhost -u root -D myschema 0< myscript.sql
(Yes, there is no password here, this is a test DB listening only to 127.0.0.1)
Anyone have an idea why this is so very slow? (See my.ini below)
[client]
port=3306
[mysql]
default-character-set=latin1
[mysqld]
port=3306
bind-address=127.0.0.1
basedir="C:/Program Files/MySQL/mysql-5.6.10-winx64/"
datadir=C:/DATA
character-set-server=latin1
default-storage-engine=myisam
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=100
query_cache_size=0
table_open_cache=256
tmp_table_size=18M
thread_cache_size=8
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=35M
key_buffer_size=25M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=256K
innodb_additional_mem_pool_size=2M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1M
innodb_buffer_pool_size=47M
innodb_log_file_size=24M
innodb_thread_concurrency=8
log-bin=c:/data/mysql/binarylog
max_binlog_size=1024M
enable-named-pipe
slow_query_log=
expire_logs_days=90
解决方案
Doh! Looks like this is a dupe. See:
Why is connecting to MySQL server so slow?
https://serverfault.com/questions/408550/connecting-to-mysql-from-php-is-extremely-slow
I've got IPv6 enabled on the 64-bit machine and not the 32-bit machine. When I connect with the following alternate string, things are much quicker:
mysql -h 127.0.0.1 -u root -D myschema 0< myscript.sql
Still not sure why this is happening, but at least there's a workaround! Alas poor localhost
I knew him well.
EDIT: The following change to my.ini allows use of localhost
in scripts and connection strings:
bind-address=::1
Note: Binding to ::ffff:127.0.0.1
or localhost
didn't seem to help. I read about binding both IPv6 and IPv4 addresses to MySQL server so all 3 connection strings would work (e.g. -h ::1
, -h 127.0.0.1
, -h localhost
). However, I was only able to get one or two of those client strings to work at a time.
EDIT2: Binding in the following way:
bind-address=*
Completely resolves this issue and both IPv4 and IPv6 clients can connect. The only drawback being that remote connections are now allowed. I haven't found a way to use TCP with localhost
restrictions and bind to both 127.0.0.1
and ::1
.
相关文章