Pages by Andreas B. M. Hofmeier
An-H
email Impressum/Note Privacy
http[s]://www.abmh.de/en/papers/ls/MySQL-Im_Export.html

Like to be free? ... then: Fight for Freedom

MySQL-Im/Export

From Linux Solutions

Jump to: navigation, search

Contents

Exporting all Databases from MySQL:

mysqldump -A -u root -p > databases.sql

root is the user to login databases.sql is the file, the exported datebases are written to


Exporting one specific Database from MySQL

mysqldump --databases db -u root -p > db.sql

root is the user to login db the database which is exported db.sql is the file, the exported datebase is written to


Importing databases

The .sql file actually contains mysql-commands which are interpreted by mysql:

cat db.sql | mysql -u root -p

root is the user to login db.sql is the database to import


If the name of the database needs to be changed, open the .sql file and replace the name of the database at least twice.

  • 1. at
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `name_of_database` /*!40100 DEFAULT 
CHARACTER SET latin1 */;
  • 2. at
USE `name_of_database`;

name_of_database states the name of the database exported and needs to be replaced by the name of the new database.


If the import fails, try to drop the database:

  • 1. login into mysql
mysql -u root -p

2. drop database

drop database `name_of_database`;

You can find a complete list with all mysql-commands under


http://www.pantz.org/database/mysql/mysqlcommands.shtml


Andreas B.M. Hofmeier


Pages by Andreas B. M. Hofmeier
An-H
email Impressum/Note Privacy
http[s]://www.abmh.de/en/papers/ls/MySQL-Im_Export.html
Creative Commons License
(c) Andreas B. M. Hofmeier
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Germany License