MySQL之使用命令导出与导入sql文件

MySQL之使用命令导出与导入sql文件

文章目录

1. 语法说明

  1. 先配置下mysql的环境变量,如果未配置则切换到mysql安装目录的bin目录下进行操作

  2. 导出语法:mysqldump -u 用户名 -p 数据库名 > (目录)xxx.sql,如果不写 > 后的导出目录,默认导出在当前目录下

  3. 导入sql文时,先登录数据库并切换到要导入的数据库,然后件使用source xxx.sql 进行导入

2. 导出SQL文件

  1. 如在F盘下导出
shell 复制代码
F:\>mysqldump -u root -p account > 20190221_5_account.sql
Enter password: ****
F:\
  1. 在导出到F:\00test\目录下
shell 复制代码
F:\>mysqldump -u root -p test > F:\00test\test.sql
Enter password: ****
F:\

3. 导入SQL文件

  1. 先登录mysql命令行交互模式中
shell 复制代码
C:\Users\Administrator>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.7.18-log MySQL Community Server (GPL)

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>
  1. 切换到要导入的数据库中
shell 复制代码
mysql> use test;
Database changed
mysql>
  1. 使用 source 命令导入
shell 复制代码
mysql> source F:\00test\test.sql
mysql>
相关推荐
inferno15 小时前
十三、存储过程(PROCEDURE)
数据库·sql·mysql
Decay__16 小时前
PostgreSQL DBA 日常运维手册 —— 会话、锁阻塞、慢查询、膨胀与每日巡检
运维·数据库·sql·postgresql
kiwixing18 小时前
GaussDB|几台机器、哪种协议:高可用部署形态与副本协议选型
数据库·sql·database·gaussdb
SongRenShuo19 小时前
三年 MyBatis 排查史:从我翻日志,到让 SQL 自己浮现
sql·mybatis·idea·日志·调试
Decay__20 小时前
PostgreSQL 安装部署实战 —— PGDG yum 源安装、initdb 初始化与 postgresql.conf 参数调优
运维·数据库·sql·postgresql
FungLeo2 天前
FengCMS · PHP+MySQL 升级实录 · 旧后台备份三宗罪:漏空表、改写内容、按分号切 SQL 直接执行
sql·mysql·php·安全加固·fengcms
ZhengEnCi3 天前
覆盖索引是什么:用借书和外卖看懂回表这件事
sql·mysql·postgresql
CoderYanger3 天前
Java EE 进阶:10. MyBatis-Plus使用(第一弹)
java·spring boot·后端·sql·spring·java-ee·mybatis
Star(up up up)3 天前
MySQL 事务隔离级别是如何实现的?从 MVCC 到锁机制原理详解
笔记·vscode·sql·学习·程序人生·mysql·学习方法
Decay__3 天前
PostgreSQL 数据库全栈运维实战系列 — 合集索引(24 篇)
运维·数据库·sql·mysql·架构