1.mysql官网下载:https://dev.mysql.com/downloads/mysql/
![](https://i-blog.csdnimg.cn/blog_migrate/d3170d8187c9d4b4f87b4aa0270dd1d5.png)
2.将下载下来的压缩包解压,并在解压后的文件下添加一个文件(my.ini),和一个文件夹(data)
![](https://i-blog.csdnimg.cn/blog_migrate/75b81498db264a87c7ad31963883ac21.png)
3.在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 是本地MYSQL的安装目录,datadir 是本地MYSQL数据库存放数据文件的位#置,各项配置需要根据自己的环境进行配置
basedir = D:\mysql-8.0.16-winx64
datadir = D:\mysql-8.0.16-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
4.初始化数据库打开cmd命令窗口:mysql --initialize --console
初始化数据库以后记住初始化以后的密码
![](https://i-blog.csdnimg.cn/blog_migrate/626f41b3c0cdd39d7615b96295d905d4.png)
5.注册mysql服务已管理员身份打开cmd 执行:mysql -install
(开机自启动)
6.执行:net start mysql 启动服务
7.使用开始保存的密码登录 :
mysql -uroot -p密码
(注意首次登录不管你怎么操作都不能正常使用mysql,需要修改初始密码,同时会报错:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.)
8.在登录以后执行:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
在MySQL8.0.4以前,执行SET PASSWORD=PASSWORD(‘[修改的密码]’); 就可以更改密码,但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。因为当前有很多数据库工具和链接包都不支持“caching_sha2_password”,为了方便,我暂时还是改回了“mysql_native_password”认证插件。
如果想默认使用“mysql_native_password”插件认证,可以在配置文件中配置default_authentication_plugin项。
9.关闭cmd窗口,从新登录mysql就可以正常使用了