phpMyAdmin管理mysql的有用小技巧

1.突破mysql導入數據庫文件最大限制的方法
遇到導入過大.sql文件時,先檢查php.ini中的upload_max_filesize,修改其值,並且推薦修改的值要稍大於導入的巨大sql數據庫文件。重啓php環境(我用的是Apache2.2),再次導入即可。(我的環境:win2003+mysql+Apache2.2+php+phpMyAdmin2.11.1.2)

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.

There exist several workarounds if your upload is too big or your hosting provider is unwilling to change the settings:

  • Look at the $cfg['UploadDir'] feature. This allows one to upload a file to the server via scp, ftp, or your favorite file transfer method. PhpMyAdmin is then able to import the files from the temporary directory. More information is available in the Configuration section of this document.
  • Using a utility (such as BigDump) to split the files before uploading. We cannot support this or any third party applications, but are aware of users having success with it.
  • If you have shell (command line) access, use MySQL to import the files directly. You can do this by issuing the "source" command from within MySQL: source filename.sql.

          數據備份和恢復

默認的數據導出、和導入最大文件有2M的最大限制。如果要操作大於2M的數據庫備份文件就需要預先將文件上傳到phpmyadmin的某個目錄。

1.首先在phpmyadmin個跟目錄建立一個目錄,比如叫ports

2.在config.default.php中搜$cfg['UploadDir'],這個變量定義保存導入文件存放的目錄,它下面的$cfg['SaveDir']定義的是數據導出文件的存放目錄,我們都定義爲ports

 

$cfg['UploadDir'] = 'ports';                    

$cfg['SaveDir'] = 'ports';

 

要注意的是ports目錄的權限,saveDir只要能讓php腳本往裏邊寫東西。最後的就是操作完了,務必清空改目錄,防止數據被別有用心的人下載。

2.導入Excel數據到Mysql中

工具:phpMyAdmin
2.1整理Excel:保證Excel中數據按MYSQL中相關表的字段順序列排列好,而且要保證列數與字段數相同(即使Mysql中首字段是auto_increment,Excel中也要包含該列,否則導入時會提示:Invalidfield count in CSV input on line 1.)。
(注意特殊字段的表示方式,例如:時間字段必須用2007-10-10形式表示,如果表示成2007-1-1,可能會導入的爲空值)。
2.2另存爲.CSV:將你的EXCEL另存爲.CSV格式(此格式中,認爲兩個字段之間是以","即逗號來表示)。
2.3找到要導入數據的表:單擊“Import”,在“File toimport”出選擇2.2步的.CSV,在“Format of importedfile”處選擇“CSV”,在“Options”處勾選“Ignore duplicaterows”,並將“分隔字段的字符”改爲“,”(英文逗號)。
2.4 單擊“執行”就OK了。
將你的字段按MYSQL中相關表的字段順序列排列好,注意特殊字段的表示方式(例如:時間字段必須用2007-10-10形式表示,如果表示成2007-1-1,可能會導入的爲空值).
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章