MySQL version: 8.0.11
方式: zip 安装
参考链接: https://www.cnblogs.com/nuomin/p/8916257.html
服务名: mysql8011 密码:root123
环境:Windows 10
. MySQL8.0 Windows zip包下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip
在安装根目录下添加 my.ini,比如我这里是:D:\Program\MySQL\my.ini,写入基本配置:
[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:\Program\MySQL
datadir = D:\DBs\MySQL\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
注意,里面的 basedir 是我本地的安装目录,datadir 是我数据库数据文件要存放的位置,各项配置需要根据自己的环境进行配置。
查看所有的配置项,可参考:https://dev.mysql.com/doc/refman/8.0/en/mysqld-option-tables.html
在MySQL安装目录的 bin 目录下执行命令:
. mysqld --initialize --console # 初始化DB,生成data文件夹下面的数据和root用户的临时密码, 日志里记录下来
e.g: 2018-05-17T05:42:01.012787Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: oQl*>Egza4fl
. mysqld --install [服务名] # 不写服务名默认mysql, e.g: mysqld --install mysql8011
. net start mysql8011 #启动MySQL的服务了
. 更改密码和密码认证插件:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root123';