1、在MySQL官网下载好MySQL-5.7.16版本的zip压缩包,并解压到相关目录,如下:
2、配置环境变量,如下:
3、修改MySQL的配置文件,复制一份默认配置文件my-default.ini并改名为my.ini,如下:
用文本工具打开my.ini文件修改其中的basedir、datadir、port,其中, basedir为MySQL安装根路径,
datadir为MySQL安装根目录下的data文件夹路径(默认没有data目录,先不用管,后续会自动创建),port为默认端口号,
如下:
# 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 = G:\coder\database\mysql-5.7.16-winx64
datadir = G:\coder\database\mysql-5.7.16-winx64\data
port = 3312
# 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
4、注册MySQL服务,以管理员的身份运行cmd命令提示符窗口并进入到MySQL安装路径下的bin目录,并执行以下命令:
mysqld -install将mysql安装到windows服务(移除服务可以用mysqld --remove);在执行mysql --initialize初始化data目录
(前文中配置的data目录在此步骤自动创建)。
5、启动MySQL服务,执行net start mysql(执行net stop mysql停止MySQL服务)如下:
6、登录root用户并更改root用户默认密码,root用户默认密码在data目录下*.err文件中,修改root用户默认密码命令:
alter user ‘root‘@‘localhost‘ identified with mysql_native_password by ‘新密码‘。如下:
注意:
1)mysqld –initialize-insecure:自动生成无密码的root用户;
2)mysqld –initialize:自动生成带随机密码的root用户;
3)mysqld -remove:移除mysqld服务;
4)net stop mysql:停止mysql服务;
5)如果报错,删除data文件夹,重新执行如下流程remove --> initialize --> install --> start