Register / Login
Win a copy of
Java Mock Exams (software)
this week in the
Programmer Certification (OCPJP)
this forum made possible by our volunteer staff, including ...
Stephan van Hulst
JDBC and Relational Databases
Pass parameters to a mysql sql file from a batch file in windows
posted 3 years ago
I have two files, create_user.bat and create_user.sql This is the content of create_user.bat :
cls mysql -uroot -proot -e "set @P_USER:='AAAAA'; set @HOST='localhost'; set @P_PW='BBBB'; set @DBNAME:='TEMPDB'; source create_generic.sql;" :END
This is the content of the .sql file :
CREATE USER '@P_USER'@'@HOST' IDENTIFIED BY '@P_PW'; CREATE DATABASE IF NOT EXISTS '@DBNAME'; GRANT ALL PRIVILEGES ON *.* TO '@P_USER'@'@HOST' IDENTIFIED BY '@P_PW' WITH GRANT OPTION;
Upon running the bat file, first it gave me this error :
ERROR 1105 (HY000) at line 16 in file: 'create_user.sql': Malformed hostname (illegal symbol: '@')
Then I changed this '@P_USER'@'@HOST' to '@P_USER'@'localhost' then I get this error :
ERROR 1396 (HY000) at line 16 in file: 'create_user.sql': Operation CREATE USER failed for '@P_USER'@'localhost'
I have read similar questions on various forums and I think am following everything. I dont see where I am going wrong. How do I go about fixing this script please?
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
Boost this thread!
Unable to drop user in mysql
Tomcat Connection pool creating too many connections, stuck in sleep mode
mysql JDBC driver classpath problem.
Problem with Connecting to mysql using java
Help - - - ClassNotFoundException: com.mysql.jdbc.Driver