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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 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/ |
| |||
| > 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 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/ |
| |||
| >> 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 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/ |
| |||
| 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 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/ |