The free-to-install version of MySQL is an excellent assistant for Software Green Publishing, and this article describes a method for automating the configuration of MySQL using batch commands. (1) Establish three files, respectively: Service Install.bat,temp.txt,update.sql. (2) write the following in the Temp.txt file: Set pathtemp= (3) writes the following in the Update.sql file: Use MySQL update user set host= '% ' where user= ' root ' and hos t= ' 127.0.0.1 '; Update user set Password=password (' root ') where user= ' root ' and host= '% '; Quit (4) writes the following in the service Install.bat file: The function of @echo off rem @echo off is to turn off the Echo function
REM Find current path REM Copies the contents of the Temp.txt file into the Temp.bat file the content in the REM temp.txt file is "set pathtemp=" REM Special Note: "=" cannot be added back to copy temp.txt Temp.bat >nul
REM adds the path to the Temp.bat file Cd>>temp.bat
REM Executes the Temp.bat file in the command rem temp.bat file after execution, the path has been saved in the PATHTEMP variable in the call Temp.bat
REM Delete temp.bat file del temp.bat
REM Set My-huge.ini marker bit set TAG=[MYSQLD]
REM Set the database path and data path added to the My.ini file the REM set datadir=datadir=%pathtemp%\data means REM sets the string "Datadir=", the variable pathtemp the corresponding string, and the string " \data "assigns a value to the DATADIR variable set basedir=basedir=%pathtemp% set Datadir=datadir=%pathtemp%\data
REM Set Run environment variable Homedir set Homedir=%pathtemp%\bin
REM Set Variable delay REM NOTE: After using variable delay, related variables are used!! Surrounded, so that the program can correctly identify setlocal enabledelayedexpansion
The REM loop finds the contents of the My-huge.ini file for/f "tokens=*"%%i in (My-huge.ini) does (
REM assigns a string that is read from the My-huge.ini file to the variable p set p=%%i
REM If the contents of the variable p and the My-huge.ini tag bits are the same REM writes the contents of the variable p to the My.ini file, adding two lines after it: the contents of the REM Basedir and the contents of the DataDir; if the REM is different, Writes the contents of the variable p to the My.ini file only if "!p!" = = "%tag%" (Echo!p!>>my.ini echo!basedir!>>my.ini echo!datadir!>>my.ini) if not "!p!" = = "%tag%" Echo!p!>>my.ini)
REM SET command to install MySQL service set Installcmd=.\bin\mysqld-nt.exe-install
REM Invoke install command call!installcmd!
REM Start MySQL service net start MySQL
REM calls the SQL statement in the Update.sql file to open the remote access of MySQL for remote access to the server; REM Also, change the MySQL password, this batch command changes the MySQL password to root. \bin\mysql-u Root <.\update.sql
The REM restart MySQL service net stop mysql net start MySQL (5) runs the service Install.bat file, completing the MySQL environment configuration, which can then be called by the program to the MySQL service.
Note: At this point, the root user password for MySQL has been changed to "root" and allows users to access MySQL remotely.