Jump to content

Help with bat and mysql


Guest jth085272

Recommended Posts

Hi all,

I am currently trying to create a bat file that asks the user for information then creates a sql file with that info. It then calls mysql and runs the sql file. Right now I got it creating the databases, not populating them yet. My issue is, once that bat file runs the root user password gets changed from whatever i have it set as to root. I don't know how this is possible.

contents of bat file:

@echo off
rem Variables
set dbstruct=DB_Structures
set sd2struct=DB_Structures\\ScriptDev2
set optim=DB_Optimizer
set mysql=.

rem Asks if databases are created.
set /p yesno=Do you have databases already created?  
if %yesno% neq n if %yesno% neq N goto dbDone

rem If answer to above question is no, comes here to ask for server info
rem and what to name databases.
set /p svr=Whats is your MySQL host name?              
if %svr%. == . set svr=localhost
set /p user=What is your MySQL user name?              
if %user%. == . set user=root
set /p pass=What is your MySQL password?               
if %pass%. == . set pass=
set /p port=What is your MySQL port[default is 3306]?  
if %port%. == . set port=3306
set /p wdb=Name you would like your World database called?          
if %wdb%. == . set wdb=mangos
set /p sd2db=Name you would like your ScriptDev2 database called?     
if %sd2db%. == . set sd2db=scriptdev2
set /p cdb=Name you would like your Characters database called?     
if %cdb%. == . set cdb=characters
set /p rdb=Name you would like your Realmd database called?         
if %rdb%. == . set rdb=realmd

rem Take inputed information to create sql file.
echo  GRANT USAGE ON * . * TO '%user%'@'%svr%' IDENTIFIED BY '%user%' WITH  MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0  ; > create_mysql2.sql
echo. >> create_mysql2.sql
echo CREATE DATABASE `%wdb%` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; >> create_mysql2.sql
echo. >> create_mysql2.sql
echo CREATE DATABASE `%cdb%` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; >> create_mysql2.sql
echo. >> create_mysql2.sql
echo CREATE DATABASE `%rdb%` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; >> create_mysql2.sql
echo. >> create_mysql2.sql
echo GRANT ALL PRIVILEGES ON `%wdb%` . * TO '%user%'@'%svr%' WITH GRANT OPTION; >> create_mysql2.sql
echo. >> create_mysql2.sql
echo GRANT ALL PRIVILEGES ON `%cdb%` . * TO '%user%'@'%svr%' WITH GRANT OPTION; >> create_mysql2.sql
echo. >> create_mysql2.sql
echo GRANT ALL PRIVILEGES ON `%rdb%` . * TO '%user%'@'%svr%' WITH GRANT OPTION; >> create_mysql2.sql

echo
echo Creating required databases.

%mysql%\\mysql -h%svr% -u%user% -p%pass% < create_mysql2.sql
echo

contents of create sql file:

GRANT USAGE ON * . * TO 'root'@'localhost'  IDENTIFIED BY 'root' WITH MAX_QUERIES_PER_HOUR 0  MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 ; 

CREATE DATABASE `MaNGOS` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 

CREATE DATABASE `Characters` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 

CREATE DATABASE `Realmd` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 

GRANT ALL PRIVILEGES ON `MaNGOS` . * TO 'root'@'localhost' WITH GRANT OPTION; 

GRANT ALL PRIVILEGES ON `Characters` . * TO 'root'@'localhost' WITH GRANT OPTION; 

GRANT ALL PRIVILEGES ON `Realmd` . * TO 'root'@'localhost' WITH GRANT OPTION;

I do apologize if this is the wrong place to post. The MySQL forums are useless. Any help is appreciated.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use