時間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評論(0)
隨著數(shù)據(jù)的增多,數(shù)據(jù)的備份顯得日益重要,下面是mysql常用的數(shù)據(jù)導入導出命令。
1.導出整個數(shù)據(jù)庫
格式:mysqldump -u 用戶名 -p 數(shù)據(jù)庫名 > 導出的文件名
舉例:
C:\Documents and Settings\Owner>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目錄里面執(zhí)行如下命令
C:\MySQL\MySQL Server 5.0\bin>mysqldump -u root -p testdb > testdb.sql
Enter password:
C:\MySQL\MySQL Server 5.0\bin>
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*/;
2.導出一個表
格式:mysqldump -u 用戶名 -p 數(shù)據(jù)庫名 表名> 導出的文件名
舉例:表結構與上面的相同,命令如下:
C:\MySQL\MySQL Server 5.0\bin>mysqldump -u root -p testdb user > user.sql
Enter password:
C:\MySQL\MySQL Server 5.0\bin>
user.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 */;
/*!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*/;
3.導出一個數(shù)據(jù)庫結構
格式:mysqldump -u 用戶名 -p -d --add-drop-table 數(shù)據(jù)庫 > 導出的文件名
說明:-d 選項表示沒有數(shù)據(jù)??
關鍵詞標簽:MySQL
相關閱讀 MySQL常用維護管理工具 MySQL數(shù)據(jù)庫啟動失敗1067進程意外終止的解決辦法總結 MySQL CPU 占用 100% 的解決過程 CentOS 6.3安裝配置LAMP服務器(Linux+Apache+MySQL+PHP5) MySQL服務器進程CPU占用100%解決辦法 WIN2003 IIS6.0+PHP+ASP+MYSQL優(yōu)化配置
熱門文章 Xbox Game Pass 10款MySQL數(shù)據(jù)庫客戶端圖形界面管理工具推薦 MySQL常用維護管理工具 MySQL數(shù)據(jù)庫啟動失敗1067進程意外終止的解決辦法總結
時間:2021-12-15 13:54:19
時間:2020-02-01 12:31:03
時間:2019-05-29 10:10:42
時間:2019-05-23 17:36:41
時間:2019-02-22 11:07:11
時間:2019-01-29 14:35:09
人氣排行 10款MySQL數(shù)據(jù)庫客戶端圖形界面管理工具推薦 MySQL數(shù)據(jù)庫啟動失敗1067進程意外終止的解決辦法總結 Mysql 1045錯誤解決辦法 MySQL服務器進程CPU占用100%解決辦法 MySQL導出導入命令的用例 MySQL連接字符串的實際操作步驟匯總 MySQL無法啟動、無法停止各種解決方法總結 三種常用的MySQL建表語句