最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL使用mysqldump實現(xiàn)數(shù)據(jù)完全備份

 更新時間:2023年07月24日 11:24:45   作者:牽著我的豬去看海  
mysqldump是MySQL自帶的備份工具,可方便實現(xiàn)對MySQL的備份,也可以將指定的庫、表導(dǎo)出為SQL腳本,下面小編就來教大家如何使用mysqldump實現(xiàn)數(shù)據(jù)完全備份吧

mysqldump備份與恢復(fù)

MySQL自帶的備份工具,可方便實現(xiàn)對MySQL的備份

可以將指定的庫、表導(dǎo)出為SQL腳本

使用命令mysql導(dǎo)入備份的數(shù)據(jù)

mysqldump -u root -p --all-databses > all-data-$(date +%F).sql ###備份所有數(shù)據(jù)庫
mysqldump -u root -p -databases auth mysql > auth-mysql.sql ###備份auth和mysql庫
mysqldump -u root -p auth > auth-$(data +%F).sql ###備份auth數(shù)據(jù)庫
mysqldump -u root -p mysql user > mysql-user-$(date +%F).sql ###備份mysql的user表
mysqldump -u root -p -d mysql user > /tmp/desc-mysql-user.sql ###備份mysql庫user表的結(jié)構(gòu)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| myadm              |
| mysql              |
| performance_schema |
| student            |
| sys                |
| tom                |
+--------------------+
7 rows in set (0.00 sec)
[root@server3 opt]# mysqldump -u root -p tom > /opt/tom.sql
Enter password: 
[root@server3 opt]# ls
tom.sql   # 導(dǎo)出的備份文件

對所有庫進行完全備份

[root@server3 opt]# mysqldump -uroot -pabc123 --all-databases > /backup/all.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.

mysqldump備份數(shù)據(jù)表

musqldump可針對庫內(nèi)特定的表進行備份

使用mysqldump備份表的操作

mysqldump -u 用戶名 -p 【密碼】【選項】選項庫名 表名 > /備份路徑/備份文件名

示例:

mysql> use tom;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------+
| Tables_in_tom |
+---------------+
| chengji       |
+---------------+
1 row in set (0.00 sec)
mysql> select * from chengji;
+----------+-------+
| name     | point |
+----------+-------+
| xiaowang |    77 |
| xiaoli   |    75 |
+----------+-------+
2 rows in set (0.00 sec)
#復(fù)制tom表 name字段 張三內(nèi)容 生成一張新表pp
mysql> create table pp as select * from chengji where name='xiaowang';
Query OK, 1 row affected (0.03 sec)
Records: 1  Duplicates: 0  Warnings: 0
mysql> show tables;
+---------------+
| Tables_in_tom |
+---------------+
| chengji       |
| pp            |
+---------------+
2 rows in set (0.00 sec)
#新生成表
mysql> select *from pp;
+----------+-------+
| name     | point |
+----------+-------+
| xiaowang |    77 |
+----------+-------+
1 row in set (0.00 sec)

[root@server3 ~]# mysql -u root -p123123 chengji pp > /opt/pp.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@server3 ~]# ls /opt
pp.sql

恢復(fù)數(shù)據(jù)庫

1、使用mysqldump導(dǎo)出的腳本,可使用導(dǎo)入的方法:

1)source命令【作用于mysql模式下】2)mysql命令【作用于于linux模式下】

2、使用source恢復(fù)數(shù)據(jù)庫的步驟

登錄到mysql數(shù)據(jù)庫

執(zhí)行source備份sql腳本的路徑

source恢復(fù)的示例

MYSQL[(none)]> source /backup/all-data.sql

模擬刪除表

mysql> use tom;
Database changed
#刪除表
mysql> drop table chengji;
Query OK, 0 rows affected (0.02 sec)
mysql> drop table pp;
Query OK, 0 rows affected (0.01 sec)

進行恢復(fù)

mysql> use tom;
Database changed
mysql> use tom;
Database changed
mysql> show tables;
+---------------+
| Tables_in_tom |
+---------------+
| tom           |
+---------------+
1 row in set (0.00 sec)
mysql> select * from tom;
+----+----------+----------+
| id | name     | address  |
+----+----------+----------+
|  1 | zhangsan | hangzhou |
+----+----------+----------+
1 row in set (0.00 sec)
mysql> insert into tom (name,address) values('lisi','wuxi');
Query OK, 1 row affected (0.00 sec)
mysql> select * from tom;
+----+----------+----------+
| id | name     | address  |
+----+----------+----------+
|  1 | zhangsan | hangzhou |
|  2 | lisi     | wuxi     |
+----+----------+----------+
2 rows in set (0.00 sec)
mysql> create table pp as select * from tom where name='zhangsan';
Query OK, 1 row affected (0.02 sec)
Records: 1  Duplicates: 0  Warnings: 0
mysql> show tables;
+---------------+
| Tables_in_tom |
+---------------+
| pp            |
| tom           |
+---------------+
2 rows in set (0.00 sec)
mysql> select * from pp;
+----+----------+----------+
| id | name     | address  |
+----+----------+----------+
|  1 | zhangsan | hangzhou |
+----+----------+----------+
1 row in set (0.00 sec)
mysql> Ctrl-C -- exit!
Aborted
[root@server3 opt]# mysqldump -u root -p tom pp > /opt/pp.sql
Enter password: 
[root@server3 opt]# ls /opt/
all.sql  opt.sql  pp.sql  rh  tom.tom
[root@server3 opt]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.36-log Source distribution
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> drop table tom;
ERROR 1046 (3D000): No database selected
mysql> use tom;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> drop table tom;
Query OK, 0 rows affected (0.01 sec)
mysql> drop table pp;
Query OK, 0 rows affected (0.00 sec)
```java
mysql> show tables;
Empty set (0.00 sec)
#恢復(fù)
mysql> source /opt/all.sql;
..省略內(nèi)容
mysql> use tom;
Database changed
mysql> show tables;
+---------------+
| Tables_in_tom |
+---------------+
| tom           |
+---------------+
1 row in set (0.00 sec)
mysql> source /opt/pp.sql;
mysql> show tables;
+---------------+
| Tables_in_tom |
+---------------+
| pp            |
| tom           |
+---------------+
2 rows in set (0.00 sec)
mysql> select * from pp;
+----+----------+----------+
| id | name     | address  |
+----+----------+----------+
|  1 | zhangsan | hangzhou |
+----+----------+----------+
1 row in set (0.00 sec)

已經(jīng)恢復(fù)  這邊我們是恢復(fù)所有數(shù)據(jù)庫  

也可以單獨的對標(biāo)進行備份恢復(fù)

到此這篇關(guān)于MySQL使用mysqldump實現(xiàn)數(shù)據(jù)完全備份的文章就介紹到這了,更多相關(guān)MySQL mysqldump數(shù)據(jù)備份內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • MySQL如何插入Emoji表情

    MySQL如何插入Emoji表情

    這篇文章主要介紹了MySQL如何插入Emoji表情,幫助大家更好的理解和使用MySQL,感興趣的朋友可以了解下
    2020-12-12
  • mysql的MVCC多版本并發(fā)控制的實現(xiàn)

    mysql的MVCC多版本并發(fā)控制的實現(xiàn)

    這篇文章主要介紹了mysql的MVCC多版本并發(fā)控制的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • MySQL優(yōu)化表時提示 Table is already up to date的解決方法

    MySQL優(yōu)化表時提示 Table is already up to date的解決方法

    這篇文章主要介紹了MySQL優(yōu)化表時提示 Table is already up to date的解決方法,需要的朋友可以參考下
    2016-11-11
  • 深入探究MySQL事務(wù)實現(xiàn)原理

    深入探究MySQL事務(wù)實現(xiàn)原理

    數(shù)據(jù)庫事務(wù)是指一組數(shù)據(jù)庫操作,這些操作必須被視為一個不可分割的單元,要么全部執(zhí)行成功,要么全部失敗回滾,本文詳細(xì)的給大家介紹了MySQL事務(wù)的實現(xiàn)原理,對我們學(xué)習(xí)MySQL有一定的幫助,感興趣的同學(xué)可以跟著小編一起來探究
    2023-06-06
  • MySQL中常用的字段截取和字符串截取方法

    MySQL中常用的字段截取和字符串截取方法

    在 MySQL 數(shù)據(jù)庫中,有時我們需要截取字段或字符串的一部分進行查詢、展示或處理,本文將介紹 MySQL 中常用的字段截取和字符串截取方法,幫助你靈活處理數(shù)據(jù),需要的朋友可以參考下
    2024-01-01
  • 介紹一個針對C++程序的MySQL訪問庫soci

    介紹一個針對C++程序的MySQL訪問庫soci

    這篇文章主要介紹了介紹一個針對C++程序的MySQL訪問庫soci,文章中還講了其中的一些操作方法,需要的朋友可以參考下
    2015-05-05
  • SQL注入漏洞過程實例及解決方案

    SQL注入漏洞過程實例及解決方案

    這篇文章主要介紹了SQL注入漏洞過程實例及解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-03-03
  • MYSQL行列轉(zhuǎn)置方式

    MYSQL行列轉(zhuǎn)置方式

    本文介紹了如何使用MySQL和Navicat進行列轉(zhuǎn)行操作,首先,創(chuàng)建了一個名為`grade`的表,并插入多條數(shù)據(jù),然后,通過修改查詢SQL語句,使用`CASE`和`IF`函數(shù)將列轉(zhuǎn)換為行,總結(jié)指出,`SUM`可以替換為`MAX`、`MIN`、`AVG`等聚合函數(shù),并且在查詢中需要對普通字段進行分組
    2025-01-01
  • mysql5.7.21安裝配置教程

    mysql5.7.21安裝配置教程

    這篇文章主要為大家詳細(xì)介紹了mysql5.7.21安裝配置教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • MySQL使用distinct去掉查詢結(jié)果重復(fù)的問題

    MySQL使用distinct去掉查詢結(jié)果重復(fù)的問題

    這篇文章主要介紹了MySQL使用distinct去掉查詢結(jié)果重復(fù)的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01

最新評論

宜君县| 临猗县| 迁西县| 珠海市| 偏关县| 资溪县| 安新县| 崇左市| 天柱县| 柯坪县| 拜城县| 黄龙县| 黑河市| 新野县| 宁陕县| 太湖县| 鄂伦春自治旗| 酒泉市| 常州市| 长岭县| 铜山县| 崇文区| 新闻| 绥化市| 深水埗区| 龙南县| 沈阳市| 奎屯市| 信阳市| 醴陵市| 博罗县| 潮安县| 开封市| 哈尔滨市| 清原| 治多县| 华阴市| 临泽县| 镇远县| 兴安盟| 汤阴县|