目录
1. 下载离线安装包
2. 上传解压
3 配置 my.ini 文件
4 设置系统环境变量
5 安装 MySQL
6 登录 MySQL
客户环境是内网环境,不能访问外网,只能离线安装 MySQL 了。
1. 下载离线安装包
MySQL 离线压缩包官网下载地址:MySQL :: Download MySQL Community Server (Archived Versions)
此次安装 8.0.20 版本!
2. 上传解压
解压后的文件目录:
可以看到,默认是没有 data 文件夹和 my.ini 文件的,则需要我们自己手动创建这两个目录和文件即可:
3 配置 my.ini 文件
[mysqld]
# 设置 3306 端口
port=3306
# 设置 mysql 的安装目录,即 bin 目录
basedir="mysql 安装目录"
# 设置 mysql 数据库的数据的存放目录,即 data 目录
datadir="mysql 安装目录再加上 \data"
# 允许最大连接数
max_connections=200
# 允许连接失败的次数
max_connect_errors=10
# 服务端使用的字符集默认为 utf8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用 “mysql_native_password” 插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
# 设置 mysql 客户端默认字符集
default-character-set=utf8
[client]
# 设置 mysql 客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
4 设置系统环境变量
5 安装 MySQL
以管理员身份启动 cmd 或 PowerShell 进行以下操作:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
PS C:\Users\Administrator> cd E:\keymanTech\dbs\mysql-8.0.20-winx64\bin
PS E:\keymanTech\dbs\mysql-8.0.20-winx64\bin> mysqld --initialize --console
2023-02-14T06:59:51.688125Z 0 [System] [MY-013169] [Server] E:\keymanTech\dbs\mysql-8.0.20-winx64\bin\mysqld.exe (mysqld 8.0.20) initializing of server in progress as process 16856
2023-02-14T06:59:51.688225Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file 'E:\keymanTech\dbs\mysql-8.0.20-winx6in\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2023-02-14T06:59:51.689181Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2023-02-14T06:59:51.712993Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-02-14T06:59:52.262250Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-02-14T06:59:53.741675Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: s-fqTBh.=7?e
但是在安装过程中有报错信息:
[ERROR] [MY-010338] [Server] Can't find error-message file 'E:\xxx\mysql-8.0.20-winx6in\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
解决办法:
查了很多教程最后发现是转义字符出现了问题:MySQL Bugs: #90364: Can't find error-message file
因为我们在配置 MySQL 安装目录的时候,没有将安装目录配置到根目录下(就是 MySQL 解压文件根目录)或者没有加双斜杠:
- 错误路径:basedir="D:\\InstalledDevsoftware\\XXX" 或 D:\InstalledDevsoftware\XXX
- 正确路径:basedir="D:\\Devsoft\\mysql-8.0.20-winx64\\XXX"
还需要在 my.ini 多加一行内容:
······
# 设置 mysql 的安装目录,即 bin 目录
basedir="E:\\xxx\\mysql-8.0.20-winx64\\bin"
# 设置 mysql 数据库的数据的存放目录,即 data 目录
datadir="E:\\xxx\\mysql-8.0.20-winx64\\data"
lc-messages-dir="E:\\xxx\\mysql-8.0.20-winx64\\share\\english"
······
再次执行 mysqld --initialize --console 命令:
报另外一个错误信息: [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
解决办法:清空 data 文件夹下的内容即可!
再次执行 mysqld --initialize --console 命令:
PS E:\keymanTech\dbs\mysql-8.0.20-winx64\bin> mysqld --initialize --console
2023-02-14T07:17:13.196681Z 0 [System] [MY-013169] [Server] E:\keymanTech\dbs\mysql-8.0.20-winx64\bin\mysqld.exe (mysqld 8.0.20) initializing of server in progress as process 19932
2023-02-14T07:17:13.196777Z 0 [Warning] [MY-010339] [Server] Using pre 5.5 semantics to load error messages from E:\keymanTech\dbs\mysql-8.0.20-winx64\share\english\. If this is not intended, refer to the documentation for valid usage of --lc-messages-dir and --language parameters.
2023-02-14T07:17:13.197450Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2023-02-14T07:17:13.219796Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-02-14T07:17:13.717398Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-02-14T07:17:15.254780Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: h5(rJyMiFKn0
PS E:\keymanTech\dbs\mysql-8.0.20-winx64\bin> mysqld --install
Service successfully installed.
PS E:\keymanTech\dbs\mysql-8.0.20-winx64\bin> net start mysql
MySQL 服务正在启动 ...
MySQL 服务已经启动成功。
在任务管理器中库看到名为 MySQL 的服务:
6 登录 MySQL
用前面随机生成的密码登录:
PS E:\xxx\mysql-8.0.20-winx64\bin> mysql -u root -p
Enter password: ************
# 修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
# 用新密码登录
PS E:\xxx\mysql-8.0.20-winx64\bin> mysql -u root -p
Enter password: **********
文章来源:https://www.toymoban.com/news/detail-451132.html
至此 MySQL 8 安装成功!!!文章来源地址https://www.toymoban.com/news/detail-451132.html
到了这里,关于Windows 离线安装 MySQL 8的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!