下载

https://downloads.mysql.com/archives/community/
image.png

解压

image.png
解压后没有my.ini 文件,需要手动创建
image.png

建立 my.ini 文件

  1. [mysqld]
  2. # 设置3306端口
  3. port=3306
  4. # 设置mysql的安装目录
  5. basedir=D:\devServer\MySQL
  6. # 设置mysql数据库的数据的存放目录
  7. datadir=D:\devServer\MySQL\Data
  8. # 允许最大连接数
  9. max_connections=200
  10. # 允许连接失败的次数。
  11. max_connect_errors=10
  12. # 服务端使用的字符集默认为utf8mb4
  13. character-set-server=utf8mb4
  14. # 创建新表时将使用的默认存储引擎
  15. default-storage-engine=INNODB
  16. # 默认使用“mysql_native_password”插件认证
  17. #mysql_native_password
  18. default_authentication_plugin=mysql_native_password
  19. [mysql]
  20. # 设置mysql客户端默认字符集
  21. default-character-set=utf8mb4
  22. [client]
  23. # 设置mysql客户端连接服务端时默认使用的端口
  24. port=3306
  25. default-character-set=utf8mb4

注意:配置中的basedir,datadir目录需要事先建立。

管理员身份,运行 cmd,进行安装

image.png

  1. D:\devServer\mysql-8.0.22-winx64\bin>mysqld --initialize --console
  2. 2021-01-19T06:14:39.997917Z 0 [System] [MY-013169] [Server] D:\devServer\mysql-8.0.22-winx64\bin\mysqld.exe (mysqld 8.0.22) initializing of server in progress as process 16240
  3. 2021-01-19T06:14:39.997969Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file 'D:\devServer\MySQL\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
  4. 2021-01-19T06:14:39.998955Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
  5. 2021-01-19T06:14:39.998962Z 0 [ERROR] [MY-013236] [Server] The designated data directory D:\devServer\MySQL\Data\ is unusable. You can remove all files that the server added to it.
  6. 2021-01-19T06:14:40.007052Z 0 [ERROR] [MY-010119] [Server] Aborting
  7. 2021-01-19T06:14:40.007771Z 0 [System] [MY-010910] [Server] D:\devServer\mysql-8.0.22-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.22) MySQL Community Server - GPL.
  8. D:\devServer\mysql-8.0.22-winx64\bin>mysqld --initialize --console
  9. 2021-01-19T06:15:15.125680Z 0 [System] [MY-013169] [Server] D:\devServer\mysql-8.0.22-winx64\bin\mysqld.exe (mysqld 8.0.22) initializing of server in progress as process 15060
  10. 2021-01-19T06:15:15.125733Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file 'D:\devServer\MySQL\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
  11. 2021-01-19T06:15:15.135848Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  12. 2021-01-19T06:15:19.565832Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  13. 2021-01-19T06:15:29.002189Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: P-)Jz2vih:3;
  14. D:\devServer\mysql-8.0.22-winx64\bin>mysqld --install
  15. Service successfully installed.
  16. D:\devServer\mysql-8.0.22-winx64\bin>net start mysql
  17. MySQL 服务正在启动 .
  18. MySQL 服务已经启动成功。
  19. D:\devServer\mysql-8.0.22-winx64\bin>mysql
  20. ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
  21. D:\devServer\mysql-8.0.22-winx64\bin>mysql -u root
  22. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  23. D:\devServer\mysql-8.0.22-winx64\bin>mysql -u root -P P-)Jz2vih:3;
  24. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  25. D:\devServer\mysql-8.0.22-winx64\bin>mysql -u root -p
  26. Enter password: ************
  27. Welcome to the MySQL monitor. Commands end with ; or \g.
  28. Your MySQL connection id is 12
  29. Server version: 8.0.22
  30. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
  31. Oracle is a registered trademark of Oracle Corporation and/or its
  32. affiliates. Other names may be trademarks of their respective
  33. owners.
  34. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  35. mysql> alter user 'root@localhost' identified by '123456';
  36. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  37. mysql> alter user 'root'@'localhost' identified by '123456';
  38. Query OK, 0 rows affected (0.04 sec)
  39. mysql> FLUSH PRIVILEGES;
  40. Query OK, 0 rows affected (0.03 sec)
  41. mysql>

命令:

初始化数据库(要注意记住初始化的临时密码):mysqld —initialize —console
安装到本地服务(服务名称默认为 mysql):mysqld —install
启动本地服务:net start mysql
需要修改密码,登录 mysql,执行命令,刷新权限:
mysql -u root -p
alter user ‘root@localhost’ identified by ‘123456’;
FLUSH PRIVILEGES;
exit

完成安装,快来使用工具连接一下 mysql 服务吧!

参考:MySQL 8.0.19安装教程(windows 64位)