import_export.rst.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. Import and export
  2. =================
  3. Import
  4. ++++++
  5. To import data, go to the "Import" tab in phpMyAdmin. To import data into a
  6. specific database or table, open the database or table before going to the
  7. "Import" tab.
  8. In addition to the standard Import and Export tab, you can also import an SQL
  9. file directly by dragging and dropping it from your local file manager to the
  10. phpMyAdmin interface in your web browser.
  11. If you are having troubles importing big files, please consult :ref:`faq1_16`.
  12. You can import using following methods:
  13. Form based upload
  14. Can be used with any supported format, also (b|g)zipped files, e.g., mydump.sql.gz .
  15. Form based SQL Query
  16. Can be used with valid SQL dumps.
  17. Using upload directory
  18. You can specify an upload directory on your web server where phpMyAdmin is installed, after uploading your file into this directory you can select this file in the import dialog of phpMyAdmin, see :config:option:`$cfg['UploadDir']`.
  19. phpMyAdmin can import from several various commonly used formats.
  20. CSV
  21. ---
  22. Comma separated values format which is often used by spreadsheets or various other programs for export/import.
  23. .. note::
  24. When importing data into a table from a CSV file where the table has an
  25. 'auto_increment' field, make the 'auto_increment' value for each record in
  26. the CSV field to be '0' (zero). This allows the 'auto_increment' field to
  27. populate correctly.
  28. It is now possible to import a CSV file at the server or database level.
  29. Instead of having to create a table to import the CSV file into, a best-fit
  30. structure will be determined for you and the data imported into it, instead.
  31. All other features, requirements, and limitations are as before.
  32. CSV using LOAD DATA
  33. -------------------
  34. Similar to CSV, only using the internal MySQL parser and not the phpMyAdmin one.
  35. ESRI Shape File
  36. ---------------
  37. The ESRI shapefile or simply a shapefile is a popular geospatial vector data
  38. format for geographic information systems software. It is developed and
  39. regulated by Esri as a (mostly) open specification for data interoperability
  40. among Esri and other software products.
  41. MediaWiki
  42. ---------
  43. MediaWiki files, which can be exported by phpMyAdmin (version 4.0 or later),
  44. can now also be imported. This is the format used by Wikipedia to display
  45. tables.
  46. Open Document Spreadsheet (ODS)
  47. -------------------------------
  48. OpenDocument workbooks containing one or more spreadsheets can now be directly imported.
  49. When importing an ODS speadsheet, the spreadsheet must be named in a specific way in order to make the
  50. import as simple as possible.
  51. Table name
  52. ~~~~~~~~~~
  53. During import, phpMyAdmin uses the sheet name as the table name; you should rename the
  54. sheet in your spreadsheet program in order to match your existing table name (or the table you wish to create,
  55. though this is less of a concern since you could quickly rename the new table from the Operations tab).
  56. Column names
  57. ~~~~~~~~~~~~
  58. You should also make the first row of your spreadsheet a header with the names of the columns (this can be
  59. accomplished by inserting a new row at the top of your spreadsheet). When on the Import screen, select the
  60. checkbox for "The first line of the file contains the table column names;" this way your newly imported
  61. data will go to the proper columns.
  62. .. note::
  63. Formulas and calculations will NOT be evaluated, rather, their value from
  64. the most recent save will be loaded. Please ensure that all values in the
  65. spreadsheet are as needed before importing it.
  66. SQL
  67. ---
  68. SQL can be used to make any manipulation on data, it is also useful for restoring backed up data.
  69. XML
  70. ---
  71. XML files exported by phpMyAdmin (version 3.3.0 or later) can now be imported.
  72. Structures (databases, tables, views, triggers, etc.) and/or data will be
  73. created depending on the contents of the file.
  74. The supported xml schemas are not yet documented in this wiki.
  75. Export
  76. ++++++
  77. phpMyAdmin can export into text files (even compressed) on your local disk (or
  78. a special the webserver :config:option:`$cfg['SaveDir']` folder) in various
  79. commonly used formats:
  80. CodeGen
  81. -------
  82. `NHibernate <https://en.wikipedia.org/wiki/NHibernate>`_ file format. Planned
  83. versions: Java, Hibernate, PHP PDO, JSON, etc. So the preliminary name is
  84. codegen.
  85. CSV
  86. ---
  87. Comma separated values format which is often used by spreadsheets or various
  88. other programs for export/import.
  89. CSV for Microsoft Excel
  90. -----------------------
  91. This is just preconfigured version of CSV export which can be imported into
  92. most English versions of Microsoft Excel. Some localised versions (like
  93. "Danish") are expecting ";" instead of "," as field separator.
  94. Microsoft Word 2000
  95. -------------------
  96. If you're using Microsoft Word 2000 or newer (or compatible such as
  97. OpenOffice.org), you can use this export.
  98. JSON
  99. ----
  100. JSON (JavaScript Object Notation) is a lightweight data-interchange format. It
  101. is easy for humans to read and write and it is easy for machines to parse and
  102. generate.
  103. .. versionchanged:: 4.7.0
  104. The generated JSON structure has been changed in phpMyAdmin 4.7.0 to
  105. produce valid JSON data.
  106. The generated JSON is list of objects with following attributes:
  107. .. js:data:: type
  108. Type of given object, can be one of:
  109. ``header``
  110. Export header containing comment and phpMyAdmin version.
  111. ``database``
  112. Start of a database marker, containing name of database.
  113. ``table``
  114. Table data export.
  115. .. js:data:: version
  116. Used in ``header`` :js:data:`type` and indicates phpMyAdmin version.
  117. .. js:data:: comment
  118. Optional textual comment.
  119. .. js:data:: name
  120. Object name - either table or database based on :js:data:`type`.
  121. .. js:data:: database
  122. Database name for ``table`` :js:data:`type`.
  123. .. js:data:: data
  124. Table content for ``table`` :js:data:`type`.
  125. Sample output:
  126. .. code-block:: json
  127. [
  128. {
  129. "comment": "Export to JSON plugin for PHPMyAdmin",
  130. "type": "header",
  131. "version": "4.7.0-dev"
  132. },
  133. {
  134. "name": "cars",
  135. "type": "database"
  136. },
  137. {
  138. "data": [
  139. {
  140. "car_id": "1",
  141. "description": "Green Chrysler 300",
  142. "make_id": "5",
  143. "mileage": "113688",
  144. "price": "13545.00",
  145. "transmission": "automatic",
  146. "yearmade": "2007"
  147. }
  148. ],
  149. "database": "cars",
  150. "name": "cars",
  151. "type": "table"
  152. },
  153. {
  154. "data": [
  155. {
  156. "make": "Chrysler",
  157. "make_id": "5"
  158. }
  159. ],
  160. "database": "cars",
  161. "name": "makes",
  162. "type": "table"
  163. }
  164. ]
  165. LaTeX
  166. -----
  167. If you want to embed table data or structure in LaTeX, this is right choice for you.
  168. LaTeX is a typesetting system that is very suitable for producing scientific
  169. and mathematical documents of high typographical quality. It is also suitable
  170. for producing all sorts of other documents, from simple letters to complete
  171. books. LaTeX uses TeX as its formatting engine. Learn more about TeX and
  172. LaTeX on `the Comprehensive TeX Archive Network <https://www.ctan.org/>`_
  173. also see the `short description od TeX <https://www.ctan.org/tex/>`_.
  174. The output needs to be embedded into a LaTeX document before it can be
  175. rendered, for example in following document:
  176. .. code-block:: latex
  177. \documentclass{article}
  178. \title{phpMyAdmin SQL output}
  179. \author{}
  180. \usepackage{longtable,lscape}
  181. \date{}
  182. \setlength{\parindent}{0pt}
  183. \usepackage[left=2cm,top=2cm,right=2cm,nohead,nofoot]{geometry}
  184. \pdfpagewidth 210mm
  185. \pdfpageheight 297mm
  186. \begin{document}
  187. \maketitle
  188. % insert phpMyAdmin LaTeX Dump here
  189. \end{document}
  190. MediaWiki
  191. ---------
  192. Both tables and databases can be exported in the MediaWiki format, which is
  193. used by Wikipedia to display tables. It can export structure, data or both,
  194. including table names or headers.
  195. OpenDocument Spreadsheet
  196. ------------------------
  197. Open standard for spreadsheet data, which is being widely adopted. Many recent
  198. spreadsheet programs, such as LibreOffice, OpenOffice, Microsoft Office or
  199. Google Docs can handle this format.
  200. OpenDocument Text
  201. -----------------
  202. New standard for text data which is being widely addopted. Most recent word
  203. processors (such as LibreOffice, OpenOffice, Microsoft Word, AbiWord or KWord)
  204. can handle this.
  205. PDF
  206. ---
  207. For presentation purposes, non editable PDF might be best choice for you.
  208. PHP Array
  209. ---------
  210. You can generate a php file which will declare a multidimensional array with
  211. the contents of the selected table or database.
  212. SQL
  213. ---
  214. Export in SQL can be used to restore your database, thus it is useful for
  215. backing up.
  216. The option 'Maximal length of created query' seems to be undocumented. But
  217. experiments has shown that it splits large extended INSERTS so each one is no
  218. bigger than the given number of bytes (or characters?). Thus when importing the
  219. file, for large tables you avoid the error "Got a packet bigger than
  220. 'max_allowed_packet' bytes".
  221. .. seealso::
  222. https://dev.mysql.com/doc/refman/5.7/en/packet-too-large.html
  223. Data Options
  224. ~~~~~~~~~~~~
  225. **Complete inserts** adds the column names to the SQL dump. This parameter
  226. improves the readability and reliability of the dump. Adding the column names
  227. increases the size of the dump, but when combined with Extended inserts it's
  228. negligible.
  229. **Extended inserts** combines multiple rows of data into a single INSERT query.
  230. This will significantly decrease filesize for large SQL dumps, increases the
  231. INSERT speed when imported, and is generally recommended.
  232. .. seealso::
  233. http://www.scriptalicious.com/blog/2009/04/complete-inserts-or-extended-inserts-in-phpmyadmin/
  234. Texy!
  235. -----
  236. `Texy! <https://texy.info/>`_ markup format. You can see example on `Texy! demo
  237. <https://texy.info/en/try/4q5we>`_.
  238. XML
  239. ---
  240. Easily parsable export for use with custom scripts.
  241. .. versionchanged:: 3.3.0
  242. The XML schema used has changed as of version 3.3.0
  243. YAML
  244. ----
  245. YAML is a data serialization format which is both human readable and
  246. computationally powerful ( <https://yaml.org> ).