程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> MySQL導出導入命令的用例

MySQL導出導入命令的用例

編輯:關於MYSQL數據庫

 隨著數據的增多,數據的備份顯得日益重要,下面是MySQL常用的數據導入導出命令。

  1.導出整個數據庫

  格式:MySQLdump -u 用戶名 -p 數據庫名 > 導出的文件名

  舉例:

  C:Documents and SettingsOwner>MySQL -u root -p

  Enter passWord:

  Welcome to the MySQL monitor.  Commands end with ; or g.

  Your MySQL connection id is 5 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> select * from user;
+--------+----------+----------+---------------+
| userid | username | passWord | email     |
+--------+----------+----------+---------------+
|    1 | aaa    | aaa    | aaaa      |
|    2 | bbb    | bbbb   | [email protected]|
+--------+----------+----------+---------------+
2 rows in set (0.00 sec)
  
MySQL> select * from user1;
+--------+----------+----------+---------------+
| userid | username | passWord | email     |
+--------+----------+----------+---------------+
|    1 | cccc   | cccc   | cccc      |
|    2 | cccc   | cccc   | [email protected]|
+--------+----------+----------+---------------+
2 rows in set (0.00 sec)

  在MySQL的bin目錄裡面執行如下命令

  C:MySQLMySQL Server 5.0bin>MySQLdump -u root -p testdb > testdb.sql

 Enter passWord:

  C:MySQLMySQL Server 5.0bin>

  testdb.sql內容如下:

-- MySQL dump 10.10
--
-- Host: localhost   Database: testdb
-- ------------------------------------------------------
-- Server version 5.0.7-beta-nt
  
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO__ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
  
--
-- Table structure for table `user`
--
  
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `userid` int(11) NOT NULL,
  `username` varchar(20) NOT NULL,
  `passWord` varchar(50) NOT NULL,
  `email` varchar(50) default NULL,
  PRIMARY KEY  (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  
--
-- Dumping data for table `user`
--
  
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
LOCK TABLES `user` WRITE;
INSERT INTO `user` S (1,'aaa','aaa','aaaa'),(2,'bbb','bbbb','[email protected]');
UNLOCK TABLES;
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
  
--
-- Table structure for table `user1`
--
  
DROP TABLE IF EXISTS `user1`;
CREATE TABLE `user1` (
  `userid` int(11) NOT NULL,
  `username` varchar(20) NOT NULL,
  `passWord` varchar(50) NOT NULL,
  `email` varchar(50) default NULL,
  PRIMARY KEY  (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  
--
-- Dumping data for table `user1`
--
  
/*!40000 ALTER TABLE `user1` DISABLE KEYS */;
LOCK TABLES `user1` WRITE;
INSERT INTO `user1` S (1,'cccc','cccc','cccc'),(2,'cccc','cccc','[email protected]');
UNLOCK TABLES;
/*!40000 ALTER TABLE `user1` ENABLE KEYS */;
  
/*!40101 SET SQL_MODE=@OLD_SQL_MODE*/;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS*/;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS*/;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT*/;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS*/;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION*/;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES*/;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved