I have set up PHP and MySQL through Xampp and have been trying to set up the practice database in chapter 9 of the book PHP and MySQL Web Development. I’ve successfully created the user, bookorama, and the database, books, but am trying to import the bookorama.sql file from the accompanying CD-Rom and keep getting an invalid syntax error.
The books says to use this command:
> mysql -h host -u bookorama -D books -p < bookorama.sql
I replaced “host” with “localhost” and “bookorama.sql” with “practice/bookorama.sql”
Per the Xampp instructions, the default area for web files is in the xampp/htdocs directory, so that’s where I’ve created the practice directory mentioned above.
I’m getting error 1064 (42000)
Though the book didn’t add one, I had to add a semicolon to the end of the above command as otherwise it just gave me another mysql line and didn’t finish the command.
What am I doing wrong that is generating this error?
try to provide absolute path to bookorama.sql, instead of “practice/bookorama.sql” type full path starting from the drive letter.
You may also try to omit the -D switch, just type
mysql -u bookorama -p books < /path/to/bookorama.sql
You can safely omit the ‘-h localhost’ since it will default to localhost if none is provided and see how I put the name of database after the -p, not before.
By the way, I don’t think you should not add semicolon because mysql is supposed to ask you for a password after you type this command, after you enter password it will just execute the statement
I tried your suggestions and it still wasn’t working, so I knew something was still not right with what I was doing. At that point I suddenly thought, “Maybe I’m not supposed to be in mysql first. Maybe I need to still be at the # prompt.”
That was it! Once I started using this file command at the # prompt, it loaded the file and your suggestions above worked just fine and I did not need to use the -h or the -D.
That also explains the whole semicolon mystery. I didn’t need to use it because I wasn’t supposed to be in mysql yet.
Well I’m notorious for trying to make things more complicated than they need to be.