(1)操作步骤

  • 备份数据库a.sql,其实就是一些建表、插入数据的操作

    mysqldump -uroot -proot test > /Users/wangchun/Desktop/a.sql

  • 还原,先登录,在创建数据库,再source执行备份的文件

    wangchundeMacBook-Pro:~ wangchun$ mysql -uroot -proot mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 13

Server version: 5.7.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> CREATE DATABASE test CHARACTER SET = utf8;

Query OK, 1 row affected (0.00 sec)

mysql> use test;

Database changed

mysql> source /Users/wangchun/Desktop/a.sql

Query OK, 0 rows affected (0.00 sec)

….