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>
相关推荐
孟意昶23 分钟前
Doris专题31-SQL手册-基础元素
大数据·数据库·数据仓库·分布式·sql·知识图谱·doris
小菜同学爱学习3 小时前
夯实基础!MySQL数据类型进阶、约束详解与报错排查
开发语言·数据库·sql·mysql
一只大袋鼠5 小时前
MyBatis 特性(三):缓存、延迟加载、注解开发
java·数据库·笔记·sql·缓存·mybatis
林三的日常7 小时前
SpringBoot + Druid SQL Parser 解析表名、字段名(纯Java,最佳方案)
java·spring boot·sql
衫水7 小时前
企业级 Text-to-SQL 完整执行流程
大数据·数据库·sql
Captain_Data8 小时前
SQL优化实战:如何让查询速度提升10倍
数据库·sql·mysql·性能优化·数据分析
其实防守也摸鱼8 小时前
怎么部署 sqli-Labs(SQL 注入练习靶场)及less1、2讲解
数据库·sql
Jasminee8 小时前
SQL 基础语法总结
sql·mysql
爱吃牛肉的大老虎8 小时前
MySQL优化之系统表分析SQL
android·sql·mysql
猿小喵9 小时前
记录一次长时间未提交事务造成的慢SQL
数据库·sql·mysql