1.下载,解压到自己喜欢的目录,并配置环境变量,在path中添加D:\Program Files\mysql-5.7.22-winx64\bin目录。目录根据自己的存放位置修改
2.如果没有my-default.ini 配置文件 就自己先创建一个同名的文件 然后 把下面代码贴进去
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[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 Files\mysql-5.7.22-winx64
datadir = D:\Program Files\mysql-5.7.22-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
#123654
# 初始化的密码
然后找到下面代码,修改对应的目录结构
basedir = D:\Program Files\mysql-5.7.22-winx64
datadir = D:\Program Files\mysql-5.7.22-winx64\data
3.向windows注册mysql服务。必须用管理员权限打开命令行,然后切换到mysql的bin目录下,输入命令:mysqld.exe –install MySql –defaults-file=”D:\Program Files\mysql-5.7.22-winx64\my-default.ini”
【D:\Program Files\mysql-5.7.22-winx64\my-default.ini】改为自己的mysqld的自己配置文件的目录。
提示:Service successfully installed
4、解决密码为空问题
首先通过 下面命令 执行跳过密码 ,此命令行会挂起。
mysqld –defaults-file=”D:\Program Files\mysql-5.7.22-winx64\my-default.ini” –console –skip-grant-tables
然后再另开一个命令行,执行下面命令,用root登陆,是因为刚开始没有密码的。
mysql -u root mysql
继续 执行下面2条命令 修改密码 和 刷新权限
update mysql.user set authentication_string=password(‘123456’) where user=’root’ and Host = ‘localhost’;
flush privileges;
最后切换回 上个命令界面执行 ctrl + C 结束挂起
5、启动/停止 服务
net start mysql 启动服务
net stot mysql 停止服务
6、查看服务启动状态
window+R
services.msc
如果密码过期, 执行跳过密码 ,此命令行会挂起。
mysqld –defaults-file=”D:\Program Files\mysql-5.7.22-winx64\my-default.ini” –console –skip-grant-tables
然后再另开一个命令行,执行下面命令,修改密码期限。
update mysql.user set password_expired=’N’ where user=’root’ and Host = ‘localhost’;
最后 结束上个页面的命令 ctrl+C 然后再执行重启服务