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>
相关推荐
红云梦3 小时前
官方 Anthropic Postgres MCP Server 存在 SQL 注入漏洞 -- SafeDB 是如何做到 4 层防御的
数据库·sql
消失的旧时光-19436 小时前
SQL 第一篇:CRUD 实战,从 user 表开始写接口
数据库·sql·mysql
悠悠121388 小时前
一条 SQL 从敲下回车,到在 MySQL 里“跑完一生”,中间到底经历了啥?
数据库·sql·mysql
山峰哥9 小时前
SQL优化从入门到精通:20个案例破解性能密码
数据库·sql·oracle·性能优化·深度优先
努力努力再努力wz9 小时前
【MySQL进阶系列】拒绝冗余SQL:带你透彻理解视图的底层逻辑
android·c语言·数据结构·数据库·c++·sql·mysql
历程里程碑9 小时前
MySQL数据类型全解析 + 代码实操讲解
大数据·开发语言·数据库·sql·mysql·elasticsearch·搜索引擎
Python大数据分析@10 小时前
有哪些好用又免费的SQL工具?
数据库·sql
HackTwoHub20 小时前
AI大模型网关存在SQL注入、附 POC 复现、影响版本LiteLLM 1.81.16~1.83.7(CVE-2026-42208)
数据库·人工智能·sql·网络安全·系统安全·网络攻击模型·安全架构
l1t20 小时前
DeepSeek总结的DuckLake构建基于 SQL 原生表格式的下一代数据湖仓
数据库·sql
yaodong5181 天前
不会Python也能数据分析:Gemini 3.1 Pro解决办公问题的SQL自动生成
python·sql·数据分析