MySQL数据库备份与恢复
1、备份
1.1、导出数据库
指令 mysqldump --host 主机 --user 用户名 --password --databases 数据库名 > 导出的文件名
[root@oracle ~]# mysqldump --host 127.0.0.1 --user root --password --databases movies > /Users/oracle/Desktop/movies.sql
此时,在桌面就是看到movies.sql文件。
2、恢复
2.1、进入MySQL
指令 mysql -u 用户名 -p
[root@oracle ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.7.11 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>
2.2、新建一个空数据库
指令 CREATE DATABASE IF NOT EXISTS db_name CHARACTER SET utf8mb4;
mysql> CREATE DATABASE IF NOT EXISTS `movies` CHARACTER SET utf8mb4;
Query OK, 1 row affected (0.00 sec)
mysql>
2.3、切换到目标数据库
指令 use db_name;
mysql> use `movies`;
Database changed
mysql>
2.4、恢复数据库
指令 source 路径/xx.sql;
mysql>source /Users/oracle/Desktop/movies.sql;
mysql>
-----------------------------------------------------------------------------------------------------------
薔薇猛虎皆成個性,陽光雨露俱是天恩!
薔薇猛虎皆成個性,陽光雨露俱是天恩!
浙公网安备 33010602011771号