Very slow (1 second) connections

偶尔善良 提交于 2019-12-10 09:53:32

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/17815604/very-slow-1-second-connections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!