使用cp指令備份MySQL資料庫

2021-09-12 04:18:55 字數 3229 閱讀 5515

mariadb [(none)]> show databases;

> +--------------------+

> | database |

> +--------------------+

> | information_schema |

> | mysql |

> | performance_schema |

> +--------------------+

> 3 rows in set (0.01 sec)

mariadb [(none)]> create database yang1;

query ok, 1 row affected (0.00 sec)

mariadb [(none)]> create database yang2;

query ok, 1 row affected (0.00 sec)

mariadb [(none)]> create database yang3;

query ok, 1 row affected (0.00 sec)

mariadb [(none)]> show databases;

> +--------------------+

> | database |

> +--------------------+

> | information_schema |

> | mysql |

> | performance_schema |

> | yang1 |

> | yang2 |

> | yang3 |

> +--------------------+

可以看到上面建立了yang1,yang2,yang3這3個資料庫。

mariadb [(none)]> use yang1

database changed

mariadb [yang1]> create table table_name (id int);

query ok, 0 rows affected (0.22 sec)

mariadb [yang1]> create table table_name2 (id int);

query ok, 0 rows affected (0.03 sec)

這裡給yang1這個資料庫新增了兩張表分別是table_name,table_name2。

[root@localhost /]# cp -a /var/lib/mysql/* /mysqlback ***//這裡是重點,保留檔案許可權***

[root@localhost /]# cd mysqlback

[root@localhost mysqlback]# ll

> 總用量 28700

> -rw-rw----. 1 mysql mysql 16384 3月 7 12:30 aria_log.00000001

> -rw-rw----. 1 mysql mysql 52 3月 7 12:30 aria_log_control

> -rw-rw----. 1 mysql mysql 18874368 3月 7 16:56 ibdata1

> -rw-rw----. 1 mysql mysql 5242880 3月 7 16:56 ib_logfile0

> -rw-rw----. 1 mysql mysql 5242880 3月 7 12:30 ib_logfile1

> drwx------. 2 mysql mysql 4096 3月 7 15:57 mysql

> srwxrwxrwx. 1 mysql mysql 0 3月 7 12:30 mysql.sock

> drwx------. 2 mysql mysql 4096 3月 7 12:30 performance_schema

> drwx------. 2 mysql mysql 65 3月 7 16:56 yang1

> drwx------. 2 mysql mysql 20 3月 7 16:50 yang2

> drwx------. 2 mysql mysql 20 3月 7 16:51 yang3

最後可以看到yang1,yang2,yang3資料庫被還原成功,2個表也成功還原。

mysql備份還原資料庫指令

mysql備份資料庫指令 首先用cmd指令開啟命令視窗,然後輸入相應的命令 1備份遠端資料庫 mysqldump u root p password h hostip databasename c backup.sql 2備份本地資料庫 mysqldump u root p password dat...

mysql的備份指令 mysql還原備份命令

進入資料庫 格式 mysql u 資料庫賬號 p 資料庫密碼 命令 mysql u root p 123456 備份資料庫命令 mysqldump u root password root database helloworld helloworld backup.sql 其他用法 1.匯出整個資料...

使用mysqldump備份MySQL資料庫

mysqldump是mysql自帶的資料庫匯出工具,windows和linux版本的都有。通過命令列使用,選項很多,估計功能也很強大,不過常用的都比較簡單。舉幾個例子 備份mysql中的所有資料庫到d db.sql中 mysqldump u root p all databases d db.sql...