MySQL-Im/Export
From Linux Solutions
Contents |
[edit]
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
[edit]
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
[edit]
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
[edit]
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.
[edit]
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