Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3144947
  • 博文数量: 206
  • 博客积分: 3409
  • 博客等级: 中校
  • 技术积分: 4066
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 10:21
个人简介

● ITPUB名人堂嘉宾 ● ChinaUnix社区博客专家 ● ChinaUnix社区Oracle板块版主 ● 优酷网认证音乐牛人:EricGuitar ● SDOUG 核心成员 ●E-mail:gaoqiangdba@163.com

文章分类

全部博文(206)

文章存档

2021年(11)

2020年(7)

2019年(7)

2016年(5)

2015年(36)

2014年(23)

2013年(15)

2012年(23)

2011年(61)

2010年(18)

分类: Mysql/postgreSQL

2015-03-04 22:33:46

  



 本文主要介绍MySQL/MariaDB数据库的简单逻辑导入、导出操作体验,操作还是非常简单易用的。


创建测试用表:
MariaDB [music]>  create table summary(id int,info char(128));
Query OK, 0 rows affected (0.05 sec)


MariaDB [music]> show tables;
+-----------------+
| Tables_in_music |
+-----------------+
| summary         |
| test            |
+-----------------+
2 rows in set (0.00 sec)

插入测试数据:
MariaDB [music]> insert into summary values(1,'Eric Gao is a Oracle DBA');
Query OK, 1 row affected (0.00 sec)


MariaDB [music]> insert into summary values(2,'Eric Gao is a MySQL DBA'); 
Query OK, 1 row affected (0.05 sec)


MariaDB [music]> insert into summary values(3,'Eric Gao is a AIX  SA'); 
Query OK, 1 row affected (0.00 sec)


MariaDB [music]> insert into summary values(4,'Eric Gao is a Linux  SA'); 
Query OK, 1 row affected (0.01 sec)


MariaDB [music]> select * from summary;
+------+--------------------------+
| id   | info                     |
+------+--------------------------+
|    1 | Eric Gao is a Oracle DBA |
|    2 | Eric Gao is a MySQL DBA  |
|    3 | Eric Gao is a AIX  SA    |
|    4 | Eric Gao is a Linux  SA  |
+------+--------------------------+
4 rows in set (0.00 sec)



执行mysqldump备份:
[root@localhost ~]# mysqldump -u root --databases music --lock-all-tables --flush-logs > /tmp/music.sql
[root@localhost ~]# cd /tmp
[root@localhost tmp]# ls -lt
total 86744
-rw-r--r--. 1 root root     1948 Mar  4 05:58 music.sql


删除数据库,已验证稍后还原效果:
MariaDB [(none)]> drop database music;
Query OK, 2 rows affected (0.03 sec)


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)


可以看到music数据库已经不在了。




还原整库:
MariaDB [(none)]> source /tmp/music.sql
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.00 sec)


Query OK, 0 rows affected (0.00 sec)


Query OK, 0 rows affected (0.00 sec)


Query OK, 1 row affected (0.00 sec)


Database changed
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.04 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, 4 rows affected (0.00 sec)
Records: 4  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.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, 4 rows affected (0.01 sec)
Records: 4  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.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.00 sec)


MariaDB [music]> 



验证数据是否已找回:
MariaDB [music]> select * from summary;
+------+--------------------------+
| id   | info                     |
+------+--------------------------+
|    1 | Eric Gao is a Oracle DBA |
|    2 | Eric Gao is a MySQL DBA  |
|    3 | Eric Gao is a AIX  SA    |
|    4 | Eric Gao is a Linux  SA  |
+------+--------------------------+
4 rows in set (0.00 sec)



OK,数据已还原!~~~

阅读(10778) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~