SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Create Table With SQL File

    Hi All

    I'm fairly new to MySQL devlopment, and Im trying to create a table in and existing MySQL database using an sql file on windows platform

    Contents of insert.sql

    CREATE TABLE `contact_details` (
    `User_ID` int(10) unsigned NOT NULL auto_increment Primary Key,
    `f_name` varchar(20) default NULL,
    `l_name` varchar(20) default NULL,
    `address1` varchar(45) default NULL,
    `postcode` varchar(7) default NULL,
    `email` varchar(60) default NULL
    );

    I copy this file into c:\program files\MySQL\MySQL Server 5.0\bin

    and try to create the tabel using the following command at the dos prompt
    the database is called test it does exist and its empty

    c:\program files\MySQL\MySQL Server 5.0\bin> mysql test < insert.sql
    but all this does is list a whole load of help info and does not create anything

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2007
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried:

    mysql source insert.sql

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks I tried the command

    c:\program files\MySQL\MySQL Server 5.0\bin> mysql test source insert.sql
    and the same thing happens. Something seem to be fundamentally wrong. Just list a load of help/configuration info

    Thanks anyway.

  4. #4
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    c:\program files\MySQL\MySQL Server 5.0\bin> mysql -D test -u root -p < insert.sql

    change root to a user of your choice
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much kleineme that works perfectly, I owe you one

  6. #6
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    note you can also run the program after you have logged into mysql simply by using
    Code:
    SOURCE filename
    and the other thing, you can store the files anywhere you want whether you call them directly in mysql or from the shell as kleineme pointed out above. you then just use the full path to the file

    i.e.
    Code:
    SOURCE c:/somedirectory/subdirectory/filename


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •