参考博文
上面链接写的很详细了,不赘述了。
我记录下最关键的几步,备份下:
第1步:解压zip。创建配置文件my.ini 放在 D:\common\mysql-8.0.23-winx64\ 目录下
[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.
basedir = D:\common\mysql-8.0.23-winx64\
datadir = D:\common\mysql-8.0.23-winx64\data
port = 3306
# server_id = .....
default_authentication_plugin=mysql_native_password
# 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
character-set-server = utf8mb4
performance_schema_max_table_instances = 600
table_definition_cache = 400
table_open_cache = 256
[mysql]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4
第2步:初始化数据库
-- 注意:执行日志会生成root账户的初始密码
D:\common\mysql-8.0.23-winx64\bin\mysqld --initialize --console
会得到下图的临时密码:
第3步:安装服务(用管理员的cmd)
D:\common\mysql-8.0.23-winx64\bin\mysqld --install mysql8
第4步:启动服务
net start mysql8
补充 :停掉服务是
net stop mysql8
第5步:用刚刚的临时密码登录 ,然后修改密码
mysql -uroot -p 回车后,输入刚刚的临时密码 -- 就是步骤2生成的临时密码
-- 注意配置选项【my.ini】
-- [mysqld]
-- 设置默认使用mysql_native_password插件认证
-- default_authentication_plugin=mysql_native_password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'j2ee';
--退出
exit;
如果中间过程出了问题,想重来一遍,可以将服务停止后移除服务,再将data目录全部删除,从第2步重来一遍