首先下载 MySQL Community Server 8.0.11:https://dev.mysql.com/downloads/mysql/
接着配置:在安装根目录下添加 my.ini,比如我这里是:D:\Program Files\MySQL\my.ini,写入基本配置:
1[mysqld]2# Remove leading # and set to the amount of RAM for the most important data3# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.4# innodb_buffer_pool_size = 128M5
6# Remove leading # to turn on a very important data integrity option: logging7# changes to the binary log between backups.8# log_bin9
10# These are commonly set, remove the # and set as required.11basedir = D:\Program Files\MySQL12datadir = D:\Program Files\MySQL\data13port = 330614# server_id = .....15
21 collapsed lines
16
17# Remove leading # to set options mainly useful for reporting servers.18# The server defaults are faster for transactions and fast SELECTs.19# Adjust sizes as needed, experiment to find the optimal values.20# join_buffer_size = 128M21# sort_buffer_size = 2M22# read_rnd_buffer_size = 2M23
24sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES25
26character-set-server = utf8mb427
28performance_schema_max_table_instances = 60029table_definition_cache = 40030table_open_cache = 25631
32[mysql]33default-character-set = utf8mb434
35[client]36default-character-set = utf8mb4
接着初始化数据库:
1mysqld --initialize --console
初始化的时候会输出日志:
12018-06-18T11:11:42.523486Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.22018-06-18T11:11:42.535721Z 0 [System] [MY-013169] [Server] D:\Program Files\MySQL\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 1303632018-06-18T11:12:14.577258Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Vwa5C>>pDVh)42018-06-18T11:12:44.048693Z 0 [System] [MY-013170] [Server] D:\Program Files\MySQL\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed
其中 Vwa5C>>pDVh)
是初始密码。
然后安装服务:
1mysqld --install
再启动服务:
1net start mysql
最后登录 MySQL Community Server 修改密码:
1# 先用初始密码登录2mysql -uroot -p
修改密码的时候要注意 MySQL Community Server版本之间的区别:
1# MySQL 8.0.4 及以前2SET PASSWORD=PASSWORD(<password>);3
4# MySQL 8.0.4 以后5ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY <password>;
这个区别是 MySQL 的密码认证插件的变化造成的,如果想默认使用 mysql_native_password 插件认证,可以在 my.ini 中配置 default_authentication_plugin 项:
1[mysqld]2default_authentication_plugin=mysql_native_password