隨著數據的增多,數據的備份顯得日益重要,下面是mysql常用的數據導入導出命令.
1.導出整個資料庫
格式:mysqldump -u username -p databases_name > databackup.sql
2.導出一個表
格式:mysqldump -u username -p database_name table_name > databackup.sql
3.導出一個資料庫結構
格式:mysqldump -u username -p -d --add-drop-table database_name > databackup.sql
說明:-d 選項表示沒有數據
--add-drop-table 選項說明在每個create語句之前增加一個drop table
4.導入資料庫
導入時常用source 命令,進入mysql資料庫控制台:
C:MySQLMySQL Server 5.0bin>mysql -u root -p
Enter password:*******
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 10 to server version: 5.0.7-beta-nt
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> use testdb;
Database changed
mysql> source testdb.sql;
Query OK, 0 rows affected (0.05 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.13 sec)
Query OK, 0 rows affected (0.10 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 2 rows affected (0.04 sec)
Records: 2 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.03 sec)
Query OK, 0 rows affected (0.09 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql>
以上信息便是mysql較常用的命令導出導入方式.
< 上頁 | 下頁 > |
---|
本文出自 「網人linux社區」 博客,請務必保留此出處http://netren.blog.51cto.com/3240427/592149
[火星人 ] mysql資料庫的導出與導入已經有463次圍觀