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>
相关推荐
l1t6 小时前
调用python函数的不同方法效率对比测试
开发语言·数据库·python·sql·duckdb
武昌库里写JAVA6 小时前
微擎服务器配置要求,微擎云主机多少钱一年?
java·vue.js·spring boot·后端·sql
z***75157 小时前
【SQL技术】不同数据库引擎 SQL 优化方案剖析
数据库·sql
Andya_net7 小时前
网络安全 | 深入理解SQL注入的原理和防范
sql·安全·web安全
chxii11 小时前
MyBatis 动态 SQL,通过 XML (如 <if>、<foreach> 等)实现灵活的 SQL 拼接。
xml·sql·mybatis
合作小小程序员小小店16 小时前
桌面开发,在线%幼儿教育考试管理%系统,基于eclipse,java,swing,mysql数据库
java·数据库·sql·mysql·eclipse·jdk
朝新_18 小时前
Spring事务和事务传播机制
数据库·后端·sql·spring·javaee
百***349520 小时前
Python连接SQL SEVER数据库全流程
数据库·python·sql
l1t1 天前
用SQL求解advent of code 2024年23题
数据库·sql·算法
DO_Community1 天前
基于AI Agent模板:快速生成 SQL 测试数据
人工智能·python·sql·ai·llm·ai编程