1. 从MySQL官网下载免安装的压缩包mysql-5.7.21-winx64.zip

2. 解压到相应的目录(此处解压到F:\mysql-5.7.21-winx64)

3. 配置环境变量,将MySQL的启动目录(F:\mysql-5.7.21-winx64\bin)添加到Path中

4. 在MySQL目录下(F:\mysql-5.7.21-winx64)创建my.ini文件,内容如下:

 

 

 

  1. ​[mysql] ​
  2. ​# 设置mysql客户端默认字符集 ​
  3. ​default-character-set=utf8 ​
  4. ​[mysqld] ​
  5. ​#设置3306端口 ​
  6. ​port = 3306 ​
  7. ​# 设置mysql的安装目录 ​
  8. ​basedir=F:\mysql-5.7.21-winx64 ​
  9. ​# 设置mysql数据库的数据的存放目录 ​
  10. ​datadir=F:\mysql-5.7.21-winx64\data ​
  11. ​# 允许最大连接数 ​
  12. ​max_connections=200 ​
  13. ​# 服务端使用的字符集默认为8比特编码的latin1字符集 ​
  14. ​character-set-server=utf8 ​
  15. ​# 创建新表时将使用的默认存储引擎 ​
  16. ​default-storage-engine=INNODB ​

 

 

5. 管理员身份运行cmd

 

切换目录:

 

​C:\Windows\system32>cd F:\mysql-5.7.21-winx64\bin​

 

 

 

生成MySQL服务:

  1. ​F:\mysql-5.7.21-winx64\bin>mysqld -install​
  2. ​Service successfully installed.​

生成data目录:

 

​F:\mysql-5.7.21-winx64\bin>mysqld --initialize-insecure --user=mysql ​
启动MySQL服务:

  1. ​C:\Windows\system32>net start mysql​
  2. ​MySQL 服务正在启动 .​
  3. ​MySQL 服务已经启动成功。​

 

 

6. 登录数据库,修改密码(默认密码为空)

 

登录数据库:

  1. ​C:\Windows\system32>mysql -uroot -p​
  2. ​Enter password:​
  3. ​Welcome to the MySQL monitor. Commands end with ; or \g.​
  4. ​Your MySQL connection id is 2​
  5. ​Server version: 5.7.21 MySQL Community Server (GPL)​

  6. ​Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.​

  7. ​Oracle is a registered trademark of Oracle Corporation and/or its​
  8. ​affiliates. Other names may be trademarks of their respective​
  9. ​owners.​

  10. ​Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.​

  11. ​mysql>​

修改密码:

 

  1. ​mysql>​
  2. ​mysql>​
  3. ​mysql> show databases;​
  4. ​+--------------------+​
  5. ​| Database |​
  6. ​+--------------------+​
  7. ​| information_schema |​
  8. ​| mysql |​
  9. ​| performance_schema |​
  10. ​| sys |​
  11. ​+--------------------+​
  12. ​4 rows in set (0.00 sec)​

  13. ​mysql> use mysql;​
  14. ​Database changed​
  15. ​mysql> update user set authentication_string=password("新密码") where User="root";​
  16. ​Query OK, 1 row affected, 1 warning (0.00 sec)​
  17. ​Rows matched: 1 Changed: 1 Warnings: 1​
  18. ​mysql> ​
  19. ​mysql>FLUSH PRIVILEGES;​