当我们在操作数据库的时候,难免会遇到数据导入导出的一些操作,今天突然学到了这个知识点,特意来给大家分享。
我用的是data的这条数据
1.使用数据
mysql> use data;
Database changed
2.显示数据库的表名
mysql> show tables;
+----------------+
| Tables_in_data |
+----------------+
| user           |
+----------------+
1 row in set (0.00 sec)
3.显示表中的数据
mysql>  select * from user;
+----+-------+----------+
| id | login | password |
+----+-------+----------+
|  1 | 张三  | 123445   |
|  2 | 李四  | 123234   |
|  3 | 王武  | 1234     |
+----+-------+----------+
3 rows in set (0.00 sec)
4.删除表中id为2的这条数据
mysql> delete from user where id = 2;
Query OK, 1 row affected (0.00 sec)
5.现在再来显示表中的数据
mysql>  select * from user;
+----+-------+----------+
| id | login | password |
+----+-------+----------+
|  1 | 张三  | 123445   |
|  3 | 王武  | 1234     |
+----+-------+----------+
2 rows in set (0.00 sec)
6.现在我们来导出这个数据库的数据,导出到c盘下面的r11.sql的这个文件里面,我们可以用下面这条命令
C:\Users\Administrator.YVDE-20150812RQ>mysqldump -uroot data>c:\r11.sql
7.当执行这条语句后没有错误信息,应该你的数据就导入成功了,我们再来看看c盘下面的这个文件。(可是这个文件有点长)
-- MySQL dump 10.13  Distrib 5.6.17, for Win64 (x86_64)
--
-- Host: localhost    Database: data
-- ------------------------------------------------------
-- Server version 5.6.4-m7
/*!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 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!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_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `login` varchar(10) DEFAULT NULL,
  `password` varchar(32) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=gbk;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `user`
--
LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES (1,'张三','123445'),(3,'王武','1234');
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!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 */;
-- Dump completed on 2015-12-11  9:48:46
8.这是我们明显的可以看到INSERT INTO `user` VALUES (1,'张三','123445'),(3,'王武','1234');
这一行中没有id为2的这条数据,说明导入已经成功了。
9.我们再次进入数据库看看
C:\Users\Administrator.YVDE-20150812RQ>mysql -uroot
10.现在我们再删除data这个数据库
mysql> drop database data;
Query OK, 1 row affected (0.01 sec)
11.现在我们在来建立数据库data2
mysql> create database data2;
Query OK, 1 row affected (0.00 sec)
12.我们再来使用data2
mysql> use data2;
Database changed
13.现在我们可以看到这个表里面没有任何数据。
mysql> show tables;
Empty set (0.00 sec)
14.现在我们可以使用一条命令help
mysql> help
它显示的是以下命令
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
notee     (\t) Don't write into outfile.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog
with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
你可以看到ource的这条命令,它的解释是在数组中得到数据库名并执行数据库中的脚本文件。
15.我们可以执行这条命令,mysql> source c:\r11.sql,注意rll.sql是我们刚才导入的数据库文件
16.现在我们可以显示这张表
mysql> show tables;
+-----------------+
| Tables_in_data2 |
+-----------------+
| book            |
| user            |
+-----------------+
2 rows in set (0.00 sec)
17.我们可以打开user这张表,它显示的是如下信息
mysql> select * from user;
+----+-------+----------+
| id | login | password |
+----+-------+----------+
|  1 | 张三  | 123445   |
|  3 | 王武  | 1234     |
+----+-------+----------+
2 rows in set (0.00 sec)
这就是数据库的导入导出操作,其实看来还是比较简单的,重要的也就两条sql语句。

最新文章

  1. [k]优雅的css
  2. web项目绝对路径与相对路径的问题
  3. Myeclipse8.6配置android_SDK,进行android开发(转载)
  4. 轻松三步教你配置Oracle—windows环境
  5. oracle操作记录
  6. LaunchCharacter
  7. 多列布局——Columns
  8. LeetCode126:Word Ladder
  9. ZOJ 1241 Geometry Made Simple
  10. 【P1835】小红花
  11. [geeksforgeeks] Lowest Common Ancestor in a Binary Search Tree.
  12. win7 32/64bit VS2010 OpenCV 2.4.9 环境配置
  13. 颜色的RGB值表示法
  14. Kubernetes-v1.12.0基于kubeadm部署
  15. table 合并内容相同的第一列
  16. 解决Oracle+Mybatis批量插入报错:SQL 命令未正确结束
  17. [Spring学习笔记 7 ] Spring中的数据库支持 RowMapper,JdbcDaoSupport 和 事务处理Transaction
  18. Rewrite MSIL Code on the Fly with the .NET Framework Profiling API
  19. 性能优化之mysql索引优化
  20. Hbase的安装与测试

热门文章

  1. C#利用反射机制创建对象
  2. linux的mount(挂载)命令详解
  3. TOJ 2776 CD Making
  4. 总结一下今天做的unity面试题(一):刚体的点击事件
  5. js 判断所选时间(或者当前时间)是否在某一时间段用于不同时间段显示不同的客服qq
  6. CSS样式基础二
  7. C# 整数转二进制字符串
  8. Linux Shell基础知识
  9. 在dede:arclist、dede:list等标签中调用附加字段
  10. servlet上传下载(任何格式的都可以)