1

I am trying to setup an install script (batch file) that will automatically create a MYSQL database and a user when we install a service, assign the user to the DB, then run the install .sql file.

Would this be correct?

@echo off
c:\mysql\bin\mysql < CREATE DATABASE hlstats;
c:\mysql\bin\mysql < CREATE USER 'username_here'@'localhost' IDENTIFIED BY 'password_here';
c:\mysql\bin\mysql < GRANT ALL ON hlstats.* TO 'username_here'@'localhost';
c:\mysql\bin\mysql < install.sql

2 Answers 2

4

You need to run those scripts with mysql other parameters. Initial 3 scripts should be run as root user as most of cases. So, command format should be like below:

mysql -uroot -p < CREATE DATABASE hlstats;

Then for install.sql as long as i believe you need to create tables inside htstats database as username_here. you need to pass those parameters with mysql command as below:

mysql -uusername_here -ppassword_here hlstats< install.sql

Sign up to request clarification or add additional context in comments.

Comments

0

Run mysql with -e option:

mysql -e 'CREATE DATABASE hlstats'

.. and check exit code on each step.

Comments

Your Answer

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