下载Mysql 8.0 地址:MySQL :: Download MySQL Installer
1、解压到对应的文件夹 D:\soft\Mysql8.0\mysql-8.0.26-winx64
2、创建my.ini 和data文件夹, 需要修改的是basedir和datadir 必须是\\
[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=D:\\soft\\Mysql8.0\\mysql-8.0.26-winx64
datadir=D:\\soft\\Mysql8.0\\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、初始化数据库,进入到bin目录下
.\mysqld --initialize --console
执行完成后,会打印 root 用户的初始默认密码,我们需要记住初始密码。
4、安装mysql服务
bin目录下
.\mysqld --install [服务名]
5、启动mysql 服务
目录C:\Windows\System32下 执行命令
.\net start mysql
6、进入mysql,修改密码
我们输入:
.\mysql -uroot -p
这时候会提示输入密码,前面记住的密码,填入即可登录成功,进入MySQL命令模式。
在MySQL中执行命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';(注意一定要有分号,这里的password是你设置的密码)
FLUSH PRIVILEGES;
修改密码验证插件,同时修改密码。
之后使用root ,3306端口,localhost,就可以登录MySQL了。