从MySQL导入导出大量数据的程序实现方法_MySQL
大家一定使用过 phpmyadmin 里面的数据库导入,导出功能,非常方便。但是在实际应用中,我发现如下几个问题:
1 数据库超过一定尺寸,比如6M 这时使用导出一般没问题,可以正确的保存到本机硬盘上面,但是导入则不行!原因是:一般的 PHP.INI 里面设置临时文件/上传文件的大小限制为2M,而phpmyadmin使用了上传的方式,造成失败。
2 导出到硬盘的 .SQL 文件在导回时,经常出现由于某些单引号的问题引起失败,造成导入失败,只能用 mysql等应用程序导入了。
我的数据库已经超过10M,所以必须解决这个问题。我的思路:
导出: 用phpmyadmin 保存数据库/表格结构,用脚本读取数据库内容并保存到文件里面!
导入: 用phpmyadmin 恢复数据库/表格结构,用脚本读取文件,然后保存到库里面!
导出程序如下:调用方法为 ****.php?table=tablename
这个简单的程序目前一次保存一个表格!!每行为一个字段的数据!!
if($table==\"\")exit();
mysql_connect(\"localhost\",\"name\",\"password\");
mysql_select_db(\"database\");
$result = mysql_query(\"select * from $table\");
if(mysql_num_rows($result) echo \"开始转换数据到文本...
\";
$handle = fopen(\"$table.txt\",\"w\");
$numfields = mysql_num_fields($result);
fputs($handle,$numfields.\"\r\n\");
for($k=0;$k {
$msg = mysql_fetch_row($result);
for($i=0;$i {
$msg[$i] = str_replace(\"\r\n\",\"&&php2000mysqlreturn&&\",$msg[$i]);
$msg[$i] = str_replace(\"\n\" ,\"&&php2000mysqlreturn&&\",$msg[$i]);
fputs($handle,$msg[$i].\"\r\n\");
}
fputs($handle,\"------- php2000 dump data program V1.0 for MySQL --------\r\n\");
}
fclose($handle);
echo \"ok\";
?>
导入的程序如下:用法同上面!
if($table==\"\")exit();
mysql_connect(\"localhost\",\"name\",\"password\");
mysql_select_db(\"database\");
$message = file(\"$table.txt\");
echo $numfields = chop($message[0]);
for($k=1;$k {
$value=\"\";
for ($i=$k;$i {
$tmp = str_replace(\"&&php2000mysqlreturn&&\",\"\r\n\",chop($message[$i]));
$value .= \"\'\".addslashes($tmp).\"\',\";
}
$tmp = str_replace(\"&&php2000mysqlreturn&&\",\"\r\n\",chop($message[$k+$numfields-1]));
$value .= \"\'\".$tmp.\"\'\";
$query = \"insert into $table values (\".$value.\")\";
echo mysql_error();
mysql_query($query);
echo $k.\" \";
}
echo \"ok\";
?>
使用方法和可能的问题!
1 导入时 file()函数可能会有问题(我的10M的数据没出现问题),可以改为 fopen()然后没次读一行!!
2 导入,导出都需要用 ftp 操作,也就是导出后,用 ftp 把数据转到本机,导入时先用ftp转移数据到服务器!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

Is the clock app missing from your phone? The date and time will still appear on your iPhone's status bar. However, without the Clock app, you won’t be able to use world clock, stopwatch, alarm clock, and many other features. Therefore, fixing missing clock app should be at the top of your to-do list. These solutions can help you resolve this issue. Fix 1 – Place the Clock App If you mistakenly removed the Clock app from your home screen, you can put the Clock app back in its place. Step 1 – Unlock your iPhone and start swiping to the left until you reach the App Library page. Step 2 – Next, search for “clock” in the search box. Step 3 – When you see “Clock” below in the search results, press and hold it and

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile
