Professional Web Applications Themes

Executing an SQL script - MySQL

Hi, I have installed Apache, PHP and MySQL on my machine in order to run a development version of a website. It is the first time that I have tried this, I have managed to get the php working OK, but I dont know how to get the SQL working. I have a .sql file which has all the CREATE TABLE and INSERT statements, but I dont know how to build this so that my development site can use the information in the database. I think that I need to execute a script of some kind, but dont really know ...

  1. #1

    Default Executing an SQL script

    Hi,

    I have installed Apache, PHP and MySQL on my machine in order to run a
    development version of a website. It is the first time that I have tried
    this, I have managed to get the php working OK, but I dont know how to get
    the SQL working. I have a .sql file which has all the CREATE TABLE and
    INSERT statements, but I dont know how to build this so that my development
    site can use the information in the database. I think that I need to execute
    a script of some kind, but dont really know how to do this. I am hoping that
    someone will be able to give me some idea as to what I have to do!

    Cheers,

    Paul


    Paul Morrison Guest

  2. #2

    Default Re: Executing an SQL script

    Paul Morrison wrote:
    > Hi,
    >
    > I have installed Apache, PHP and MySQL on my machine in order to run a
    > development version of a website. It is the first time that I have tried
    > this, I have managed to get the php working OK, but I dont know how to get
    > the SQL working. I have a .sql file which has all the CREATE TABLE and
    > INSERT statements, but I dont know how to build this so that my development
    > site can use the information in the database. I think that I need to execute
    > a script of some kind, but dont really know how to do this. I am hoping that
    > someone will be able to give me some idea as to what I have to do!
    >
    > Cheers,
    >
    > Paul
    >
    >
    several methods:

    - from inside the "mysql" tool, use
    source filename.sql

    - from the command line,
    mysql -u USER -pPASSWORD database_name < filename.sql

    [url]http://dev.mysql.com/doc/refman/5.0/en/batch-commands.html[/url]

    ciao
    gmax

    --
    _ _ _ _
    (_|| | |(_|>< The Data Charmer
    _|
    [url]http://datacharmer.blogspot.com/[/url]
    Giuseppe Maxia Guest

  3. #3

    Default Re: Executing an SQL script

    > several methods:
    >
    > - from inside the "mysql" tool, use
    > source filename.sql
    >
    > - from the command line,
    > mysql -u USER -pPASSWORD database_name < filename.sql
    Thank you, one further question, is there anywhere in particular that I need
    to put the sql file?

    Cheers,

    Paul


    Paul Morrison Guest

  4. #4

    Default Re: Executing an SQL script

    Paul Morrison wrote:
    >> several methods:
    >>
    >> - from inside the "mysql" tool, use
    >> source filename.sql
    >>
    >> - from the command line,
    >> mysql -u USER -pPASSWORD database_name < filename.sql
    >
    > Thank you, one further question, is there anywhere in particular that I need
    > to put the sql file?
    >
    No. Anywhere it is readable to you, as user, is fine. If it is not in your
    current directory, use an absolute path

    $ mysql -u USER -pPASSWORD database_name < /home/username/samples/filename.sql

    mysql> source /home/username/samples/filename.sql
    > Cheers,
    >
    > Paul
    >
    >
    ciao
    gmax

    --
    _ _ _ _
    (_|| | |(_|>< The Data Charmer
    _|
    [url]http://datacharmer.blogspot.com/[/url]
    Giuseppe Maxia Guest

  5. #5

    Default Re: Executing an SQL script

    >> Thank you, one further question, is there anywhere in particular that I
    >> need
    >> to put the sql file?
    >>
    >
    > No. Anywhere it is readable to you, as user, is fine. If it is not in your
    > current directory, use an absolute path
    >
    > $ mysql -u USER -pPASSWORD database_name <
    > /home/username/samples/filename.sql
    >
    > mysql> source /home/username/samples/filename.sql
    Sorry for asking so many questions, but your help is much appreciated. How
    do I know what my current directory is? I am using Windows, will that make a
    difference? The file that I want to execute is located at
    C:\Server\Apache2\htdocs\includes\4justice.sql.

    Cheers,

    Paul


    Paul Morrison Guest

  6. #6

    Default Re: Executing an SQL script

    Paul Morrison wrote:
    >>> Thank you, one further question, is there anywhere in particular that I
    >>> need
    >>> to put the sql file?
    >>>
    >> No. Anywhere it is readable to you, as user, is fine. If it is not in your
    >> current directory, use an absolute path
    >>
    >> $ mysql -u USER -pPASSWORD database_name <
    >> /home/username/samples/filename.sql
    >>
    >> mysql> source /home/username/samples/filename.sql
    >
    > Sorry for asking so many questions, but your help is much appreciated. How
    > do I know what my current directory is?
    in Unix:
    $ pwd

    in Windows, inside a dos prompt,

    C> cd
    (and probably your prompt has already the current directory)
    > I am using Windows, will that make a
    > difference?
    If you don't know where you are, the OS is not important :)
    > The file that I want to execute is located at
    > C:\Server\Apache2\htdocs\includes\4justice.sql.
    >
    If you don't know where you are, but you know the absolute path, use it!
    Did you try this command?

    mysql> source C:\Server\Apache2\htdocs\includes\4justice.sql
    > Cheers,
    >
    > Paul
    >
    ciao
    gmax

    --
    _ _ _ _
    (_|| | |(_|>< The Data Charmer
    _|
    [url]http://datacharmer.blogspot.com/[/url]
    Giuseppe Maxia Guest

  7. #7

    Default Re: Executing an SQL script

    Hi,

    I have made a bit of progress here, I have looked at the tutorial on
    MySql.com and have made a bit of headway. I have created the 4justice
    database which is now in the Data folder of MySql. I have also done:
    mysql -u root -p PASSWORD 4justice < 4justice.sql
    which does something and some text scrolls, but it doesnt actually put
    anything into the 4justice database. Am I missing something here? I assumed
    that this would create the database for me, but it does not.

    Cheers,

    Paul


    Paul Morrison Guest

  8. #8

    Default Re: Executing an SQL script

    Paul Morrison wrote:
    > Hi,
    >
    > I have made a bit of progress here, I have looked at the tutorial on
    > MySql.com and have made a bit of headway. I have created the 4justice
    > database which is now in the Data folder of MySql. I have also done:
    > mysql -u root -p PASSWORD 4justice < 4justice.sql
    > which does something and some text scrolls, but it doesnt actually put
    > anything into the 4justice database. Am I missing something here? I assumed
    > that this would create the database for me, but it does not.
    >
    > Cheers,
    >
    > Paul
    >
    >
    To create the database, you need to issue a SQL command
    "CREATE DATABASE db_name"
    If it is not in the script, you need to do it manually.

    Moreover, notice that there must not be a space between "-p" and PASSWORD

    ciao
    gmax

    --
    _ _ _ _
    (_|| | |(_|>< The Data Charmer
    _|
    [url]http://datacharmer.blogspot.com/[/url]
    Giuseppe Maxia Guest

Similar Threads

  1. Problem when executing SQL script from AzMan BizRule
    By Sebastian Torres in forum ASP.NET Security
    Replies: 0
    Last Post: February 9th, 07:08 PM
  2. Problem when executing SQL script from AzMan BizRule.
    By Storrear in forum ASP.NET Security
    Replies: 0
    Last Post: February 9th, 06:07 PM
  3. Executing php from with a perl script
    By John Michael in forum PHP Development
    Replies: 3
    Last Post: November 28th, 05:03 AM
  4. #24457 [Fbk->NoF]: Segfault when executing a script
    By sniper@php.net in forum PHP Development
    Replies: 0
    Last Post: July 28th, 10:33 AM
  5. #24457 [Fbk->Opn]: Segfault when executing a script
    By s dot vanvelthem at ibelgique dot com in forum PHP Development
    Replies: 0
    Last Post: July 22nd, 08:07 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139