MySQL/Language/Import/export

Aside from mysqldump (cf. MySQL/Administration), you can also export / import raw data.

Export data
Data can be exported using the "INTO OUTFILE" keyword Beware that the MySQL daemon itself will write the file, not the user you run the MySQL client with. The file will be stored on the server, not on your host. Moreover, the server will need write access to the path you specify (usually, the server can _not_ write in your home directory, e.g.). Hence why we (unsecurely) used  in the examples.

You can also use the command line to export data

mysql < query.txt > output.txt

where query.txt contains an sql-query and the output will be stored in output.txt

Import data
In another database/computer/etc. the data can be imported: additional options are to specify how the document is set up and whether there is a header. The columns in the data file can be mapped to the columns of the database table if they do not correspond and it is thus also possible to omit certain columns using a dummy variable: In this example, we only need the second and third column of the data file and store these values in the name and phone_number column of our database table.

Content precisions
To import a .sql which creates a user and its database, one should know if this user already exists on the server, because MySQL doesn't have any. On the contrary it works with the databases:

PS: if this commande returns "DROP DATABASE" statements are disabled with PhpMyAdmin, modify  by switching   to , and empty the navigator cache.

MySQL/Importer/exporter