1、下载zip包
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26-winx64.zip
2、解压之后在mysql的home目录下编辑my.ini(没有的话自己新建)
[mysqld]
default_authentication_plugin=mysql_native_password
# 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=C:/mysoft/mysql-8.0.26-winx64
datadir=C:/mysoft/mysql-8.0.26-winx64/data
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
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
3、以管理员身份运行cmd,执行以下命令
# 1、创建data目录并初始化,记住输出的密码
mysqld --initialize --console
# 2、安装服务
mysqld --install [服务名]
# 3、启动服务
net start 服务名
# 4、进入mysql命令模式,输入前面的临时密码
mysql -uroot -p
# 5、修改root用户密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
FLUSH PRIVILEGES;
4、创建数据库,用户,授权等
CREATE DATABASE IF NOT EXISTS xxljob DEFAULT CHARSET UTF8 COLLATE utf8_general_ci;
# 数据库名带特殊字符的
CREATE DATABASE IF NOT EXISTS `xxl-job` DEFAULT CHARSET UTF8 COLLATE utf8_general_ci;
CREATE database if NOT EXISTS `xxl-job` default character set utf8 collate utf8_general_ci;
create user 'xxl'@'localhost' identified by 'xxl';
grant all privileges on `xxljob`.* to xxl@'localhost';
grant create,alter,drop,select,insert,update,delete on `xxl-job`.* to xxl@'localhost';
flush privileges;
=============================================
常见问题:
1、Install/Remove of the Service Denied!
解决:使用管理员身份运行cmd。
2、MySQL 服务无法启动,使用mysqld --console查看日志,发现Failed to find valid data directory
解决:data目录最好不要手动创建,删除手动创建的data目录,使用mysqld -remove 服务名移除服务,按上述步骤再来一遍。