Register / Login
Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of
Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA)
this week in the
JDBC and Relational Databases
Pass parameters to a mysql sql file from a batch file in windows
posted 2 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?
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