How Do I Run A Create SQL Script for MySQL?

Posted on 2007-10-19
Last Modified: 2008-08-28
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.
Question by:AndoverIT
    LVL 3

    Accepted Solution

    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?

    Author Comment

    Yes I do - will give it a try and get back asap.
    LVL 2

    Assisted Solution

    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.
    LVL 3

    Expert Comment

    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!

    Author Comment

    Thanks guys - am going to run it later today and hopefully confirm poits afterwards.

    Thanks in the meantime

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article describes some very basic things about SQL Server filegroups.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    The viewer will learn how to count occurrences of each item in an array.
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now