记一次mysql 导入15M的SQL文件出错调试过程

问题:用navicat 导入15M的SQL文件 ,报错  [Err] 2006 - MySQL server has gone away   

搜索出来解决方案是(非常多的坑,且听下面慢慢分解):

在my.conf(这货是linux的,win是my.ini,坑啊,还好顺便看到一个软件叫search everything,比win自带的搜索功能强大多了,一秒就搜索出来了。原来在C:\ProgramData\MySQL\MySQL Server 5.6下面)里面增加两行代码, 如:

max_allowed_packet=500M
connect_timeout = 43200

好了,保存。上面方案也没说修改完就重启mysql啊(坑啊),自己觉得肯定需要重启啊,于是在win服务里面,找到mysql,重启之,我去,重启不了了!!!!坑啊。

 

没办法,怀疑是不是Mysql5.7的问题,毕竟java8,tomcat8也都有点问题,于是重新下载5.6版本的,先是一顿删除程序,再重启,再重新安装,满怀希望重新修改my.ini文件之后,发现还是重启不了。又搜,发现是不是需要通过命令来重启服务,

net stop mysql56 (你的服务名)

net start mysql56 (你的服务名)

 注,1  、通过CMD来运行的时候,还需要获得CMD管理员权限(在开始菜单的搜索框张收入cmd,然后右键单击,并选择以管理员身份运行!),否则会报错  发生系统错误 5 拒绝访问 

      2、获得权限后,会报错:服务正在启动或停止中,请稍候片刻后再试一次。别慌,任务管理器里面 关掉所有mysql的进程。

好了,解决后,发现命令还是启动不了服务,报错:

 MySQL 服务正在启动 ...................

MySQL 服务无法启动。

请键入 NET HELPMSG 3523 以获得更多的帮助。

终于,看到一篇博客(地址:http://blog.csdn.net/u013243986/article/details/52585668),原来是这样的,他的博客里面有点问题(小坑),正确的应该是用,格式-》转为UTF-8 无BOM编码格式,保存。start 成功!!

继续导入SQL文件,还是同样的错误,mysql gone away。终于无意中在stackoverflow看到一句话(地址:http://stackoverflow.com/questions/10474922/error-2006-hy000-mysql-server-has-gone-away,但是问题主采用的 还是上面的修改my.ini的方法,在我这是不行的),这句话就是

A couple things could be happening here;

  • Your INSERT is running long, and client is disconnecting. When it reconnects it's not selecting a database, hence the error. One option here is to run your batch file from the command line, and select the database in the arguments, like so;

$ mysql db_name < source.sql

  • Another is to run your command via php or some other language. After each long - running statement, you can close and re-open the connection, ensuring that you're connected at the start of each query.

,完美的解释了问题的原因和解决方案。多谢了。

于是看来通过navicat是不行了,那我就用source命令来导入吧,打开commad line ,输入密码--

use dbName

source D:\your.sql

 

 OK,执行成功,表已经全部导入进去了。

希望给后来者一个参考。自从mysqlm卖给ORACLE后,我发觉mysql越来越难用了,想当年,毕业设计用的mysql,多简单方便啊。JAVA也是,卖给ORACLE后,感觉后继无力。。。

 
再者,希望大家有条件的情况下多写原创的博客,不要复制了,好多方案根本解决不了。浪费时间。
 
那个搜索小软件地址:http://www.voidtools.com/
 
附:
http://dev.mysql.com/doc/refman/5.5/en/replication-features-max-allowed-packet.html 写道
max_allowed_packet sets an upper limit on the size of any single message between the MySQL server and clients, including replication slaves. If you are replicating large column values (such as might be found in TEXT or BLOB columns) and max_allowed_packet is too small on the master, the master fails with an error, and the slave shuts down the I/O thread. If max_allowed_packet is too small on the slave, this also causes the slave to stop the I/O thread.

Row-based replication currently sends all columns and column values for updated rows from the master to the slave, including values of columns that were not actually changed by the update. This means that, when you are replicating large column values using row-based replication, you must take care to set max_allowed_packet large enough to accommodate the largest row in any table to be replicated, even if you are replicating updates only, or you are inserting only relatively small values.

 官网都写了, max_allowed_packet 这货是用来当字段值太大(BOLB ,TEXT这种)时候用来扩容的,跟我的脚本大完全不是一回事啊。大家都有点钻研精神多好。这点老外领先我们太多。
附二:
写道
BOM: Byte Order Mark
UTF-8 BOM又叫UTF-8 签名,其实UTF-8 的BOM对UFT-8没有作用,是为了支援UTF-16,UTF-32才加上的BOM,BOM签名的意思就是告诉编辑器当前文件采用何种编码,方便编辑器识别,但是BOM虽然在编辑器中不显示,但是会产生输出,就像多了一个空行,
 
 

猜你喜欢

转载自cainiao1923.iteye.com/blog/2334833