1、到官网下载mysql 5.7.16 zip包(略)
1)右键单击我的电脑->属性->高级系统设置(高级)->环境变量
点击系统变量下的新建按钮
输入变量名:MYSQL_HOME
输入变量值:D:\mysql\mysql-install
即为mysql的自定义解压目录。
2)选择系统变量中的Path
点击编辑按钮
在变量值中添加变量值:
;%MYSQL_HOME%\bin
2、修改新建my.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.
[client]
port=3306
default-character-set=utf8
[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:\mysql\mysql-install
datadir = D:\mysql\mysql-data\data
port = 3306
server_id = 1
# 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
# 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.
[client]
port=3306
default-character-set=utf8
[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:\mysql\mysql-install
datadir = D:\mysql\mysql-data\data
port = 3306
server_id = 1
# 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
3、进入解压路径,执行指令:
mysqld --console
4、执行指令:mysqld --initialize
出现如下错误:
意思上应该是少了个名data的文件夹。在my.ini文件的datadir路径后面追加data,同时在对应的路径下新建data文件夹。重新执行指令mysqld --initialize。成功通过。
5、执行指令:mysqld install
DOC提示:Install/Remove of the Service Denied
解决方法,打开cmd.exe程序的时候选择“用管理员身份打开”。
成功后的截图:
6、启动mysql服务:net start mysql
7、修改 root 账号的密码
1). 修改MySQL的配置文件(my.ini),在[mysqld]下添加一行skip-grant-tables
2) mysql 重启后,即可直接用 mysql -u root -p 进入(此时密码为空)
3) mysql> update mysql.user set authentication_string=password('XXXX') where user='root' and Host = 'localhost';
4) mysql> flush privileges;
5) mysql> quit;
6) 将my.cnf文件还原(删除skip-grant-tables这一行),重新启动 mysql
7) 这个时候可以使用 mysql -uroot -pXXXX 进入了
8) mysql>SET PASSWORD = PASSWORD('123456'); 设置新密码
最后截图: