[TOC] ## windows msi版本安装 ### 1、下载并完成安装 ### 2、安装目录下添加my.init文件、data文件夹 ```ini [client] port=3306 default-character-set=utf8 [mysqld] # 设置为自己MYSQL的安装目录 basedir=C:\Program Files\MySQL\MySQL Server 5.7 # 设置为MYSQL的数据目录 datadir=C:\Program Files\MySQL\data port=3306 character_set_server=utf8 sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER #开启查询缓存 explicit_defaults_for_timestamp=true ``` ### 3、使用管理员权限打开cmd 初始化数据库文件,初始化成功后,会在datadir目录下生成一些文件 ``` mysqld --initialize ``` 注册mysql服务:【将mysqld.exe添加到系统服务里】 ``` # 方式1 mysqld --install # 方式2:使用sc进行添加,注意=号后面有空格 sc create MySQL57 binPath= "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe" start= auto ``` 对应的启动服务方式: 方式1安装时,则在服务中手动启动; 方式2安装时,可以用命令启动: ```cmd #MySQL57 为服务名 net start MySQL57 #默认服务名为MYSQL,则 net start MYSQL ``` ### 4、修改密码 - 跳过授权表,启动mysql `mysqld --console --skip-grant-tables --shared-memory` - 管理员权限打开另外一个cmd窗口,执行命令`mysql -uroot`,回车后,即可进入mysql。 - 修改密码: ``` mysql> use mysql; mysql>update MySQL.user set authentication_string=password('root') where user='root'; mysql>flush privileges; mysql>quit; ``` ### 5、问题解决: ```shell PS D:\ProgramForWork\MysqlServer5.7\bin> .\mysqld --initialize mysqld: Could not create or access the registry key needed for the MySQL application to log to the Windows EventLog. Run the application with sufficient privileges once to create the key, add the key manually, or turn off logging for that application. ``` 问题原因:windows操作系统为家庭版,管理员权限问题;使用管理员权限打开`cmd`、清理data下的文件,重试即可。 > 参考安装教程: > https://blog.csdn.net/qq_35257875/article/details/93530381 > https://blog.csdn.net/qq_41417259/article/details/89716196