Create MySQL Database with .SQL File

给你一囗甜甜゛ 提交于 2019-11-30 05:22:06
rizzz86

1) Create a file "filename.sql"

2) Create a database in your DB in which you want to import this file.

3) From command-prompt/terminal, move to the directory where you have created a "filename.sql".

4) Run the command: mysql -u username -p password database_name < filename.sql. (You can also give the proper path of your file and run this command from anywhere). It might be the case that you don't have a password set for MySQL. If so, mysql -u username database_name < filename.sql will also work.

In your case if you have created a database with name ojs and also created a file with name ojs.sql in C: drive then run the following command:

Edit: Put the path inside quotes.

mysql -u username -p password ojs < "C:\ojs.sql"

There is another way of importing tables in mysql. You can do it this way as well:

1) Connect your database

2) Type command "use ojs;"

3) Type command "source C:/ojs.sql"

Steven

Most MySQL SQL files that create databases create the database 'on-the-fly', so you typically needn't do anything except:

  1. log-in

    mysql -u [username] -p[password]

(Note: make sure you do NOT include a space (' ') character between the -p and the [password]. MySQL will think that [password] is the name of the database you want to connect to. The 'general' log-in (above) does not assume you want to connect to any particular schema.)

  1. source the file (do not use quotes around filename)

    mysql> source [database_creation_file].sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!