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>
相关推荐
Habibei1 小时前
Mybatis的分页插件
sql·mybatis
吃汤圆的抹香鲸1 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
火云牌神16 小时前
本地大模型编程实战(25)用langgraph实现基于SQL数据构建的问答系统(4)
sql·llm·qwen·langgraph·deepseek
追寻光16 小时前
MySQL 中如何查看 SQL 的执行计划?
数据库·sql·mysql
是懒羊羊吖~16 小时前
SQL------搭建sql靶场和打开sql靶场及报错解决
数据库·笔记·sql·mysql·phpstudy·sqli-labs
温柔小胖17 小时前
seacmsv9 SQL注入漏洞
数据库·sql·网络安全
Komorebi.py18 小时前
关于order by的sql注入实验
sql
汤汤upup19 小时前
面试八股文--数据库基础知识总结(1)
数据库·sql·oracle
i建模20 小时前
React + TypeScript 实现数据库逆向生成数据模型指南
sql·typescript·前端框架·react·数据建模·逆向工程·数据模型
火云牌神1 天前
本地大模型编程实战(22)用langchain实现基于SQL数据构建问答系统(1)
python·sql·langchain·llama·qwen2.5