Warning: Illegal string offset 'top' in /www/wwwroot/hellyhua.com/wp-content/themes/Snape/single.php on line 45

Add Comment在使用PhpMyAdmin的时候经常用到数据的导入和导出(Export/Import),但是在导入大数据的时候由于php上传文件的限制和脚本响应时间的限制,导致phpMyAdmin无法导入大数据,对于导入大数据到mysql的,我以前使用过使用SHELL的方式导入几百兆的文件到mySQL数据库(原文),但是国内的虚拟主机绝大多数不像DreamHost一样开放SHELL权限,而且多数都是Windows Server服务器。我们自己又没有权限修改php.ini文件,对于这种情况我们可以使用phpMyAdmin提供的$cfg[‘UploadDir’]方法,导入服务器上存在的.sql文件。

首先,找到phpMyAdmin的目录,找到根目录下的config.inc.php文件,然后找到 $cfg[‘UploadDir’] ,通过注释(Directories for saving/loading files from server)就可以看出这是用来导入服务器上的SQL文件的方法。相对的就是 $cfg[‘SaveDir’] ,顾名思义就是把导出的SQL文件保存在服务器上的目录中。

修改这个参数

$cfg[‘UploadDir’] = ‘ImportSQLFile’;
$cfg[‘SaveDir’] = ‘ExportSQLFile’;

然后在phpMyAdmin中建立两个文件夹,ImportSQLFile和ExportSQLFile,一个用作大数据的导入,一个用作数据导出备份。

然后把我们需要导入的sql文件复制到ImportSQLFile中,上传到服务器上,选择需要导入的数据库名,选择导入(Import),就会发现在文件导入(File to import)的地方多出来一个导入服务器上的SQL文件(web server upload directory)

通过这种方法可以突破php.ini的上传文件限制,极限我没有试过,我上传的10M .sql文件成功导入到mysql中。

同理在导出/备份mysql数据的时候也可以直接保存在服务器上,保存到$cfg[‘SaveDir’] = ‘ExportSQLFile’;中指定的文件夹中

————————————
附上 通过修改php.ini的方法
到网上搜索了一下前人的解决办法,大多数都说修改php.ini中的upload_max_filesize,但修改了这个以后,还是提示这个问题;但 phpmyadmin在提示这个问题的时候,右下角有一行英文提示,大致意思是说,解决这个问题,可以参考 phpmyadmin文档;直接点击这个链接,phpmyadmin自动查找到了以下说明:

[1.16] I cannot upload big dump files (memory, http or timeout problems).

Starting with version 2.7.0, the import engine has been re–written and these problems should not occur. If possible, upgrade your phpMyAdmin to the latest version to take advantage of the new import features.

The first things to check (or ask your host provider to check) are the values of upload_max_filesize, memory_limit and post_max_size in the php.ini configuration file. All of these three settings limit the maximum size of data that can be submitted and handled by PHP. One user also said that post_max_size and memory_limit need to be larger than upload_max_filesize.

以上文件大致说明的意思就是说,遇到导入过大文件时,首先检查php.ini 配置文件中的以下三个地方,upload_max_filesize, memory_limit 和post_max_size,并且推荐修改的值要稍大于导入的巨大sql数据库文件;依照这个提示,修改了以上三个在php.ini中的值以后,重启了 php环境,再次导入时,虽然 phpmyadmin还是显示导入最大限制:20,480 KB,但巨大的80M数据库文件已经被成功的导入了。


Warning: Illegal string offset 'footer' in /www/wwwroot/hellyhua.com/wp-content/themes/Snape/single.php on line 49