将 mysql blob 字段从一个数据库复制到另一个数据库
我碰巧有一个数据库,其中的图片存储为 blob 字段。没办法,这是之前开发商的选择。
现在我需要在新站点中使用该数据,而提供商不允许我以简单的方式复制数据(文件已变为 11Mb 大 - 不会上传该数据,而且我没有 shell 访问权限)。 所以我想编写一个脚本来打开 db1 中的连接,选择所有记录,然后将每个记录复制到新 db2 中的表中。
如果我排除斑点,一切正常。如果我也想复制它们,它就不会插入。
有人以前有过类似的事情吗? 在插入时我应该以不同的方式对待斑点吗?
感谢您的任何想法或帮助。
I happen to have a database with pictures stored as blob fields. Can't help it, it was the previous developer's choice.
Now I need that data in a new site and the provider won't let me copy the data the easy way (file has become 11Mb big - won't upload that and I don't have shell access).
So I thought I'd write a script that opens a connection in db1, selects all the records, and then copies each into a table in the new db2.
Works all fine if I exclude the blobs. If I want to copy them too, it won't insert.
Anyone had something similar before?
Should I treat the blobs differently when it comes to inserting?
Thanks for any ideas or help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
11MB 并不是一个大文件,我很惊讶您的主机的最大上传大小如此之低。
您是否考虑过导出为 SQL,将文件分成两部分(在 Notepad++ 或其他工具中),然后以较小的部分上传?不会花很长时间。
11MB isn't a huge file, I'm surprised your host has such a low max upload size.
Have you thought about exporting as SQL, splitting the file in two (in Notepad++ or something) then uploading it in smaller sections? Wouldn't take long.
也许检查一下是否可以增加 mysql 数据库上的 max_allowed_packet 设置。我不确定它是否会影响插入,但我记得当我开发一个允许用户从数据库中的 blob 字段下载 3-5MB 二进制文件的 Web 应用程序时,必须调整此设置。
通过快速谷歌搜索,此链接可能会有所帮助:http://www. astahost.com/info.php/max_allowed_packet-mysql_t2725.html
Perhaps check to see if you can increase the max_allowed_packet setting on your mysql DB. I'm not sure if it affects inserts, but I remember having to adjust this setting when I worked on a web-app that allowed users to download 3-5MB binaries from blob fields in the DB.
This link may be helpful, from a quick google search: http://www.astahost.com/info.php/max_allowed_packet-mysql_t2725.html