0.下载指定版本mysql (例如: 5.7.29)
https://dev.mysql.com/downloads/mysql/
1. 添加配置文件 my.ini
解压目录下添加 my.ini 配置文件, 自定义安装目录 basedir 和数据目录 datadir
2. 设置环境变量, (目的是 cmd命令不必再进入mysql的bin目录下执行, 可以全局执行, 系统默认搜寻环境变量下的命令器)
设置系统变量 MYSQL_HOME, 内容是 D:\DevTools\mysql\mysql-5.7.29-winx64
编辑系统变量 PATH, 添加 %MYSQL_HOME%\bin;
3. mysql初始化, 此时会生成密码需要记一下
mysqld --initialize --console
4. 安装mysql
mysqld --install
5. 启动mysql服务
net start mysql
6. 登录mysql, 输入生成的密码
mysql -uroot -p
7. 修改密码, 此处修改为 admin123456
ALTER USER 'root'@'localhost' IDENTIFIED BY 'admin123456';
8. 退出命令
输入exit; 或者quit;
9. 用新密码登录
输入 mysql -uroot -p , 然后输入密码
或者直接输入
mysql -uroot -padmin123456
my.ini 配置文件:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# 设置mysql的安装目录
basedir = D:\\soft\mysql\mysql-5.7.29
# 设置mysql数据库的数据的存放目录
datadir = D:\\soft\mysql\mysql-5.7.29\data
# 设置3306端口
port = 3306
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 允许最大连接数
max_connections = 200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors = 10
# 服务端使用的字符集默认为UTF8
character-set-server = utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine = INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin = mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set = utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set = utf8mb4