• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1036
  • Last Modified:

How Do I Run A Create SQL Script for MySQL?

Does anyone have any simple instructions on setting up a pre-prepared MySQL Database? The instructions given were:

"The database can be created from the command line using the createdb.sql script. Alternatively the schema.sql and data.sql scripts can be imported individually (in that order)."

If someone could post some easy instructions on doing both you can have the points. There is currently no database setup on the hosting space.
  • 2
  • 2
2 Solutions
I guess something like this:
1) go to the directory where your msyql-executable is located
2)  mysqladmin -u root -pyourpassword -h servername create yourdatabasename
3)  mysql -u root -pyourpassword -h servername yourdatabasename < createdb.sql

do you have root acces to create a database?
AndoverITAuthor Commented:
Yes I do - will give it a try and get back asap.
Dont forget...

You will still need to execute the SQL commands in the Scheme and Data files.
The command
 mysql -u root -pyourpassword -h servername yourdatabasename < createdb.sql

might need a -d in front of yourdatabase, it is easy to figure out....just enter  mysql --help on the command line and it will explain the - parameters.  
The < is a pipe, this tells the operating system to send the contents of the file named to the standard input device (STDIN or CON) associated with the program mysql....basically MySql thinks you are typing in the commands.

So do the same command
mysql -u root -pyourpassword -h servername yourdatabasename < createdb.sql
mysql -u root -pyourpassword -h servername yourdatabasename < scheme.sql
mysql -u root -pyourpassword -h servername yourdatabasename < data.sql

Oh...FYI...Scheme is the term for Definition, a scheme defines the table struncture and relationships, the data.sql is most likely a bunch of SQL insert commands.
no, I don't think you have to run to import these scheme.sql and data.sql.

Because the createdb.sql contains - I assume - also the create and insert statements etc. Because the text provided by AndoverIT clearly mentiones: "***Alternatively*** the schema.sql and data.sql scripts can be imported individually (in that order)." This is just a intermediate solution if you have NOT root acces and thus cannot create database, but since by AndoverIT has root access, it will not be necessary, and importing the createdb.sql will be enough.

Running importing scheme.sql and data.sql will only result in a lot of errors!
AndoverITAuthor Commented:
Thanks guys - am going to run it later today and hopefully confirm poits afterwards.

Thanks in the meantime
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now