Home  >  Article  >  Database  >  How to install mysql in bat

How to install mysql in bat

藏色散人
藏色散人Original
2023-02-16 09:29:452253browse

bat method to install mysql: 1. Download the compressed package version of mysql; 2. Right-click the "MySQL installation.bat" file and run it as administrator; 3. Initialize the database; 4. Through "net start MySQL" to start the MYSQL service.

How to install mysql in bat

The operating environment of this tutorial: Windows 10 system, MySQL version 5.7, Dell G3 computer.

How to install mysql in bat?

Use bat to install mysql with one click

1. Download the compressed package version of mysql. The download address is as follows:

 https:// cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.22-winx64.zip

2. The directory after decompression is as follows:

 

3. Save the following content as a bat file, put the bat file in the directory just now, and then right-click and run as administrator

@setlocal enabledelayedexpansion
@echo off
color f0
rem 编程技术 www.vcvb.cn 出品,转载请保留此信息。
title MYSQL一键安装set basedir=%~dp0set bin=%~dp0\bin
cd /d %~dp0if exist !bin!\mysqld.exe (
rem 写入配置>my.ini echo [mysqld]>>my.ini echo port=3306>>my.ini echo basedir=!basedir!
>>my.ini echo datadir=!basedir!\Data>>my.ini echo log-error=!basedir!\Logs.log>>my.ini echo max_connections=200>>my.ini echo max_connect_errors=10>>my.ini echo character-set-server=utf8mb4>>my.ini echo default-storage-engine=INNODB>>my.ini echo default_authentication_plugin=mysql_native_password>>my.ini echo local_infile=ON>>my.ini echo.>>my.ini echo [mysql]>>my.ini echo default-character-set=utf8mb4>>my.ini echo local_infile=ON>>my.ini echo.>>my.ini echo [client]>>my.ini echo port=3306>>my.ini echo default-character-set=utf8mb4

rem 添加环境变量
echo 开始检查环境变量...
echo.for /f "tokens=2*" %%i ^in ('reg query "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path^|findstr /i "path"') ^do (set "p=%%j")for /f "tokens=*" %%a in ('echo !p! ^| find /i "!bin!"') do (set flag=1)if not defined flag (
echo 开始添加环境变量
setx Path "!p!;!bin!" /M | find "成功" && echo 环境变量添加成功set p=!Path!) else (echo 环境变量已存在,无需设置。)
echo.

rem 初始化 --console
cd !bin!

>!basedir!\Logs.log echo --------初始化数据库开始--------echo 开始初始化数据库

mysqld --initialize-insecure>>!basedir!\Logs.log echo --------初始化数据库结束--------rem 安装服务
echo 开始安装服务
mysqld --install MySQL | find "successfully" && echo 服务安装成功
echo.
rem 启动服务
echo 开始启动MYSQL服务
net start MySQL
echo. 

mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1qaz'";

echo 安装完成
) else (
echo 请将本工具放在解压后的MYSQL根目录下再打开
)
pause >nul

3. The installation is completed and the password has been set to: 1qaz

Note: If the dll is missing during the installation, please install vc runtime and try again

Note: If you want to reinstall, remember to delete the data in the data directory first.

Recommended study: "MySQL Video Tutorial"

The above is the detailed content of How to install mysql in bat. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn