首先在官网下载MySQL5.7.11免安装版,进行解压。打开文件夹,修改my-default.ini 拷贝一份,改名 my.ini,复制下面的配置信息到 my.ini 保存
[plain] view plain copy
1. # server_id = .....
2. basedir=D:\Program Files\MySQL\mysql-5.7.11-winx64
3. datadir=D:\Program Files\MySQL\mysql-5.7.11-winx64\data
4. port=3306
5. server_id = 10001
6.
7. # Remove leading # to set options mainly useful for reporting servers.
8. # The server defaults are faster for transactions and fast SELECTs.
9. # Adjust sizes as needed, experiment to find the optimal values.
10. join_buffer_size = 128M
11. sort_buffer_size = 2M
12. read_rnd_buffer_size = 2M
13.
14. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES </span>
1. # server_id = .....
2. basedir=D:\Program Files\MySQL\mysql-5.7.11-winx64
3. datadir=D:\Program Files\MySQL\mysql-5.7.11-winx64\data
4. port=3306
5. server_id = 10001
6.
7. # Remove leading # to set options mainly useful for reporting servers.
8. # The server defaults are faster for transactions and fast SELECTs.
9. # Adjust sizes as needed, experiment to find the optimal values.
10. join_buffer_size = 128M
11. sort_buffer_size = 2M
12. read_rnd_buffer_size = 2M
13.
14. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES </span>
1. <span style="font-size:14px;"># For advice on how to change settings please see
2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
3. # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
4. # *** default location during install, and will be replaced if you
5. # *** upgrade to a newer version of MySQL.
6.
7. [mysqld]
8.
9. # Remove leading # and set to the amount of RAM for the most important data
10. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
11. innodb_buffer_pool_size = 128M
12.
13. # Remove leading # to turn on a very important data integrity option: logging
14. # changes to the binary log between backups.
15. # log_bin
16.
17. # These are commonly set, remove the # and set as required.
18. # basedir = .....
19. # datadir = .....
20. # port = .....
解压后以及创建my.ini后截图如下
接下来就是修改环境变量:
(1)右键单击我的电脑->属性->高级系统设置(高级)->环境变量
点击“系统变量”下的新建按钮
输入变量名:MYSQL_HOME
输入变量值:D:\Program Files\MySQL\mysql-5.7.11-winx64
即为mysql的自定义解压目录。
(2)选择“系统变量”中的Path
点击编辑按钮
在变量值中添加变量值:%MYSQL_HOME%\bin
注意是在原有变量值后面加上这个变量,用;隔开,不能删除原来的变量值。在win10系统下修改环境变量比较简单不用“;”,如下图所示
管理员身份运行cmd,这一点很重要,进入到mysql的解压目录下。先初始化Data目录:以前5.6版本自带data目录,不需要这一步!如果没有这一步会无法启动mysql服务,报错MYSQL 服务无法启动,在初始化之前,务必将data目录底下的文件删除掉。
在CMD窗口中输入以下命令:
[plain] view plain copy
1. mysqld --initialize-insecure
这里比较慢,要等一会。
接着输入mysqld install进行安装注册,安装成功之后,启动服务,输入以下命令:
net start mysql
备注一下:移除安装是mysqld remove;mysqld --initialize-insecure自动生成无密码的root用户;mysqld --initialize是自动生成随机密码用户;
然后就可以登陆了。
mysql -u root -p
回车即可登录。如果提示要输入密码的时候,按个回车就登录进去了。
这是由于我们前面使用的是mysqld --initialize-insecure,因此这个时候的root密码为空,
修改登录密码
mysql> set password for 用户名@localhost = password('新密码');
例子:
mysql> set password for root@localhost = password('1234');
这个例子将用户root的密码更改为1234,此时不能立马生效,需要重新启动才能生效。