How to convert .sql file to tables in mysql db(如何将 .sql 文件转换为 mysql db 中的表)
问题描述
我有 .sql 文件,我猜是自动生成的.我没有生成这个文件,但无论如何它包括数据库名称和所有带有字段的表.我想将数据库和表添加到我的 mysql localhost 并想知道如何做到这一点.我尝试上传文件,但不断收到有关我的 sql 语法的错误.语法在我看来都是正确的,所以也许 .sql 文件需要更改?
I have .sql files that I'm guessing is auto-generated. I did not generate this file, but anyway it includes the database name and all tables with fields. I'd like to add the db and tables to my mysql localhost and would like to know how to do this. I have tried uploading the file but keep getting errors about my sql syntax. The syntax looks all correct to me so perhaps the .sql file needs to be changed?
推荐答案
来自命令行:
mysql -u root -p databaseName < file.sql
其中 databaseName 是一个已经创建的空数据库,file.sql 是您拥有的 .sql 文件,当您运行命令时,您必须与该文件位于同一文件夹中.这也假设使用 root 作为用户并且它受密码保护.根据您自己的设置进行修改.
Where databaseName is an already created empty database and file.sql is the .sql file you have, you must be in the same folder as the file when you run the command. This also assumes using root as the user and that it is password protected. Modify as needed for your own setup.
此外,您还可以通过翻转尖括号将数据库转储到文件来执行相反的操作.如下图.
Additionally, you can do the reverse by flipping the angled bracket to create a database dump to a file. Like below.
mysql -u root -p databaseName > file.sql
这篇关于如何将 .sql 文件转换为 mysql db 中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 .sql 文件转换为 mysql db 中的表
基础教程推荐
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 无法解决整理冲突 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
