如何将.sql文件转换为mysql db中的表 [英] How to convert .sql file to tables in mysql db

查看:434
本文介绍了如何将.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中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆