1

I am working in WindowsXP . My need is to create a database and restore that
database with data.sql file using batch script . This is needed while user configures the project . I tried the following method but it doesn't work for me.

// createdb.bat 
// Password is empty

@echo off 
mysql -u root -p < mysql.sql

//mysql.sql
CREATE DATABASE newdb ;

And i have both files in my Desktop . Any help please ?

5
  • 1
    Do you get any error or it just does nothing? Commented Apr 9, 2013 at 11:23
  • Does the mysql root account have no password? Try supplying the password via mysql -u root -pPASSWORD < mysql.sql. Or if the script is failing because newdb already exists, try adding drop database newdb; before the create database line. Commented Apr 9, 2013 at 12:12
  • how do you invoke createdb.bat? Commented Apr 9, 2013 at 15:24
  • I didn't get any error while running the batch file . The command window came and gone but no database is created. There is no database with a name "newdb". I checked with sql yog . Actually i invoke the createdb.bat using Runtime in java . For checking purpose i just double click to run the batch file. Commented Apr 10, 2013 at 3:32
  • It might be a path/current directory issue - the file can't be found from where the batch is running. Add if not exist mysql.sql echo Cant find mysql.sql file! before the line where it is used. And add a line of just pause as the last line, so you get a chance to see what's happened before the window vanishes. Commented Apr 10, 2013 at 12:21

1 Answer 1

2

Thanks for every one to reply my question . As Fuzzy Button said , that was a path issue . I have to set the path to xps.sql file . I have just created the createdb.bat with this code it is working well .

@echo off 
set root=C:\Documents and Settings\Administrator
cd %root%
mysql -u root  -e "CREATE DATABASE IF NOT EXISTS xps";
mysql -u root  xps < xps.sql    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.