MySql 批处理安装不同的端口号3307 的服务实例,并设置自定义的账户和密码

MySql 批处理安装不同的端口号 实例

需要准备 install.bat, mysql.ini, create_user.sql 三个文件,内容分别如下。

install.bat 内容

@echo off

echo 启动mysql并更新密码
"c:\mysql57\bin\mysqld.exe" --initialize-insecure --console --explicit_defaults_for_timestamp

"c:\mysql57\bin\mysqld.exe" install MySql57 --defaults-file=c:\mysql57\my.ini
net start MySql57
sc config MySql57 start=auto

ping -n 5 127.1>nul

echo "install mysql"
"c:\mysql57\bin\mysql.exe" --port=3307 -uroot --skip-password -e "CREATE DATABASE IF NOT EXISTS my_db"
"c:\mysql57\bin\mysql.exe" --port=3307 -uroot --skip-password <"c:\mysql57\create_user.sql" --default-character-set=utf8
net stop MySql57
net start MySql57

 

mysql.ini 内容

[mysql]

default-character-set=utf8

[client]

[mysqld]

#设置3306端口

port = 3307
basedir=c:\mysql57
datadir=c:\mysql57\data

# 允许最大连接数

max_connections=200
character-set-server=utf8
default-storage-engine=INNODB

 

create_user.sql

flush privileges;
set password for root@localhost = password('123456');
CREATE USER 'root'@'%' IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
flush privileges;
quit

 

posted @ 2024-01-09 10:30  涵旭  阅读(60)  评论(0编辑  收藏  举报