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>
相关推荐
rockey6272 小时前
基于AScript的SQL脚本语言发布啦!
sql·c#·.net·script·expression·动态脚本
持敬chijing7 小时前
Web渗透之SQL注入-堆叠注入(Stacked Queries Injection)
sql·安全·web安全·网络安全·网络攻击模型·安全威胁分析
Full Stack Developme7 小时前
SQL 执行顺序 及 全部关键字
数据库·sql
渣渣盟7 小时前
MySQL DQL全面解析:从入门到精通
数据库·sql·mysql·dql
CodeStats12 小时前
从JDBC时代到MyBatis封神:SQL全流程手写ORM实战
sql·mysql·mybatis
程序猿乐锅13 小时前
【MySQL | 第七篇】 索引使用规则
数据库·sql·mysql
Full Stack Developme13 小时前
行锁如何影响并发“修改再查询”场景
sql
zuYM4g7Dp14 小时前
文顶顶iOS开发数据库篇—SQL
数据库·sql·ios
稷下元歌14 小时前
七天学会plc加机器视觉之AI 接入 外设模块开发全详细操作文档(全程配套视频按文档实操)
python·sql·qt·贪心算法·r语言·wpf·时序数据库
tedcloud12314 小时前
FluentFlyout部署教程:打造更美观的Windows桌面环境
数据库·人工智能·sql·学习·自动化