Unix Technical Forum

Executing an SQL script

This is a discussion on Executing an SQL script within the MySQL forums, part of the Database Server Software category; --> Hi, I have installed Apache, PHP and MySQL on my machine in order to run a development version of ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:17 AM
Paul Morrison
 
Posts: n/a
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:17 AM
Giuseppe Maxia
 
Posts: n/a
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

http://dev.mysql.com/doc/refman/5.0/...-commands.html

ciao
gmax

--
_ _ _ _
(_|| | |(_|>< The Data Charmer
_|
http://datacharmer.blogspot.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 08:17 AM
Paul Morrison
 
Posts: n/a
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 08:17 AM
Giuseppe Maxia
 
Posts: n/a
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
_|
http://datacharmer.blogspot.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 08:17 AM
Paul Morrison
 
Posts: n/a
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 08:17 AM
Giuseppe Maxia
 
Posts: n/a
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
_|
http://datacharmer.blogspot.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 08:17 AM
Paul Morrison
 
Posts: n/a
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 08:17 AM
Giuseppe Maxia
 
Posts: n/a
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
_|
http://datacharmer.blogspot.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com