@[TOC]
下载
- 地址:https://dev.mysql.com/downloads/mysql/
1 一键安装
1.1 启动延迟扩展模式
@setlocal enabledelayedexpansion @echo off
1.2 切换盘符到bat所在路径
rem 切换到bat文件所在目录 %~d0 cd %~dp0
1.3 新建data文件夹
title MySQL_installing... rmdir /s /q data mkdir data
1.4 设置变量
rem 设置变量 set base=%~dp0 set basedir=%base:~0,-1% set bindir=%~dp0bin set datadir=%~dp0data set logerror=%~dp0Logs.log set slowlog=!datadir!\slow.log
1.5 新建my.ini并写入配置
> my.ini echo [mysql] >> my.ini echo default-character-set=utf8 rem 服务配置 >> my.ini echo [mysqld] >> my.ini echo port = 3306 >> my.ini echo basedir=!basedir! >> my.ini echo datadir=!datadir! >> my.ini echo log-error=!logerror! >> my.ini echo user=mysql >> my.ini echo default_authentication_plugin=mysql_native_password >> my.ini echo max_connections=1500 >> my.ini echo character-set-server=utf8mb4 >> my.ini echo innodb_buffer_pool_size=3072M >> my.ini echo wait_timeout=100 >> my.ini echo interactive_timeout=300 >> my.ini echo thread_cache_size=100 >> my.ini echo default-time_zone='+8:00' >> my.ini echo long_query_time=4 >> my.ini echo slow_query_log='ON' >> my.ini echo slow_query_log_file=!slowlog! >> my.ini echo binlog_format="STATEMENT" >> my.ini echo binlog_expire_logs_seconds=2592000 >> my.ini echo general_log=1 rem 客户端配置 >> my.ini echo [client]
1.6 安装mysql服务并初始化数据库
cd %~dp0/bin echo =============installing............ rem Initialization password mysqld --initialize-insecure --user=mysql rem installation mysqld --install MySQL rem startmysql net start mysql echo =============initializing.......... rem login mysql -uroot --skip-password -P3306 < ../logicfeng.sql
1.7 初始化文件
- 修改密码和开启远程调用
-- 修改root密码: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'logicfeng'; -- 创建用户 并 允许所有主机链接 CREATE USER 'logicfeng'@'%' IDENTIFIED WITH mysal_native_password BY 'logicfeng'; -- 赋予用户权限 这里给了所有权限,可以根据自己需要自己设置 grant all on *.* to 'logicfeng'@'%';
1.8 添加环境变量
rem 添加环境变量 if not %MYSQL_HOME% == %basedir% setx MYSQL_HOME "%basedir%" /M set string=%PATH% echo %string% | findstr /C:"%bindir%" && ( echo contains ) || ( setx path "%path%;%%MYSQL_HOME%%bin" /M )
1.9 全部代码如下,复制放到与bin目录同级即可使用
@setlocal enabledelayedexpansion @echo off rem 切换到bat文件所在目录 %~d0 cd %~dp0 rem color f0 title MySQL_installing... rmdir /s /q data mkdir data rem 设置变量 set base=%~dp0 set basedir=%base:~0,-1% set bindir=%~dp0bin set datadir=%~dp0data set logerror=%~dp0Logs.log set slowlog=!datadir!\slow.log rem 写入my.ini配置 rem 命令行工具配置 > my.ini echo [mysql] >> my.ini echo default-character-set=utf8 rem 服务配置 >> my.ini echo [mysqld] >> my.ini echo port = 3306 >> my.ini echo basedir=!basedir! >> my.ini echo datadir=!datadir! >> my.ini echo log-error=!logerror! >> my.ini echo user=mysql >> my.ini echo default_authentication_plugin=mysql_native_password >> my.ini echo max_connections=1500 >> my.ini echo character-set-server=utf8mb4 >> my.ini echo innodb_buffer_pool_size=3072M >> my.ini echo wait_timeout=100 >> my.ini echo interactive_timeout=300 >> my.ini echo thread_cache_size=100 >> my.ini echo default-time_zone='+8:00' >> my.ini echo long_query_time=4 >> my.ini echo slow_query_log='ON' >> my.ini echo slow_query_log_file=!slowlog! >> my.ini echo binlog_format="STATEMENT" >> my.ini echo binlog_expire_logs_seconds=2592000 >> my.ini echo general_log=1 rem 客户端配置 >> my.ini echo [client] rem 添加环境变量 if not %MYSQL_HOME% == %basedir% setx MYSQL_HOME "%basedir%" /M set string=%PATH% echo %string% | findstr /C:"%bindir%" && ( echo contains ) || ( setx path "%path%;%%MYSQL_HOME%%bin" /M ) rem 安装mysql服务 cd %~dp0/bin echo =============installing............ rem Initialization password mysqld --initialize-insecure --user=mysql rem installation mysqld --install MySQL rem startmysql net start mysql echo =============initializing.......... rem login mysql -uroot --skip-password -P3306 < ../logicfeng.sql echo =============completed pause
2 一键卸载
- 停止mysql服务
- 删除注册表
- 同样与bin目录同级使用
@echo off chcp 65001 %~d0 cd %~dp0 net stop mysql reg delete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\Application\MySQLD Service" /f reg delete HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\MySQL /f reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\MySQL /f reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControl001\Services\MySQL /f reg delete HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\Application\nginx /f rd /s /q data echo 卸载完成......................... pause