windows 下安装 mysql-8.0.25 解压版

介绍

此文介绍 mysql-8.0.25-winx64 的 zip 解压版,在 windows 下的安装与配置过程。

官方下载

官网下载页: https://downloads.mysql.com/archives/community/

进入官网,选择默认版本就行,不需要包含测试工具套件的版本

windows 下安装 mysql-8.0.25 解压版_第1张图片

本地解压

将下载的 mysql-8.0.25-winx64.zip 安装包,解压到任意盘符目录下,本示例解压到 C:\Program Files\mysql-8.0.25-winx64

创建 data 目录,用户存放 mysql 的数据库文件;

创建 my.ini 配置文件,用于配置 mysql 服务核心配置项;

windows 下安装 mysql-8.0.25 解压版_第2张图片

 

编辑 my.ini 配置

将以下配置复制到 my.ini 文件中,相关配置项参见配置说明

[mysqld]
#设置3306端口
port=3306
#设置mysql的安装目录
basedir="C:\\Program Files\\mysql-8.0.25-winx64"
#设置mysql数据库的数据的存放目录
datadir="C:\\Program Files\\mysql-8.0.25-winx64\\data"
#允许最大连接数
max_connections=200
#允许连接失败的次数。
max_connect_errors=10
#服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
#设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
#设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4

配置系统环境变量

在电脑》属性》高级系统设置》高级》环境变量..》系统变量 区域

新建:MYSQL_HOME = C:\Program Files\mysql-8.0.25-winx64

windows 下安装 mysql-8.0.25 解压版_第3张图片

找到 Path 变量,编辑,在最未尾加上:% MYSQL_HOME%\bin

windows 下安装 mysql-8.0.25 解压版_第4张图片

命令行初始化

用管理员打开命令行,按以下步骤一步步执行安装过程;

控制台初始化 mysql 服务;

PS C:\Program Files\mysql-8.0.25-winx64\bin> mysqld --initialize --console
2022-12-07T08:30:41.518587Z 0 [System] [MY-013169] [Server] C:\Program Files\mysql-8.0.25-winx64\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 23024
2022-12-07T08:30:41.526947Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2022-12-07T08:30:41.526962Z 0 [ERROR] [MY-013236] [Server] The designated data directory C:\Program Files\mysql-8.0.25-winx64\data\ is unusable. You can remove all files that the server added to it.
2022-12-07T08:30:41.530932Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-12-07T08:30:41.532152Z 0 [System] [MY-010910] [Server] C:\Program Files\mysql-8.0.25-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.25)  MySQL Community Server - GPL.
PS C:\Program Files\mysql-8.0.25-winx64\bin> mysqld --initialize --console
2022-12-07T08:30:41.518587Z 0 [System] [MY-013169] [Server] C:\Program Files\mysql-8.0.25-winx64\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 23024
2022-12-07T08:30:41.526947Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2022-12-07T08:30:41.526962Z 0 [ERROR] [MY-013236] [Server] The designated data directory C:\Program Files\mysql-8.0.25-winx64\data\ is unusable. You can remove all files that the server added to it.
2022-12-07T08:30:41.530932Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-12-07T08:30:41.532152Z 0 [System] [MY-010910] [Server] C:\Program Files\mysql-8.0.25-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.25)  MySQL Community Server - GPL.
PS C:\Program Files\mysql-8.0.25-winx64\bin> mysqld --initialize --console
2022-12-07T08:31:35.077814Z 0 [System] [MY-013169] [Server] C:\Program Files\mysql-8.0.25-winx64\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 23668
2022-12-07T08:31:35.088112Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-12-07T08:31:36.623504Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-12-07T08:31:39.259680Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: oh;bZjw:xxxx

需要注意:初始化完成后的未位行 “[Server] A temporary password is generated for root@localhost: oh;bZjw:xxxx”,其中的 oh;bZjw:xxxx 为 root 用户的初始化密码,需要提前记录,否则忘记后无法进入 mysql 数据库,则需要重新初始化安装生成新的 root 密码; 

安装 mysql 服务

PS C:\Program Files\mysql-8.0.25-winx64\bin> mysqld --install mysql_server
The service already exists!
The current server installed: "C:\Program Files\mysql-8.0.25-winx64\bin\mysqld.exe" mysql_server

启动 mysql 服务

PS C:\Program Files\mysql-8.0.25-winx64\bin> net start mysql_server
mysql_server 服务正在启动 .
mysql_server 服务已经启动成功。

任务管理器中查看 mysql 服务运行状态为 “正在运行”。

windows 下安装 mysql-8.0.25 解压版_第5张图片

 

修改 mysql 密码

如果密码有特殊符号是无法被命令行解析,则用 ' 单引号包住密码

PS C:\Program Files\mysql-8.0.25-winx64\bin> mysql -u root -p'oh;bZjw:xxxx'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.25
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
# 修改root密码为123456
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)

到此 mysql-8.0.25 的 zip 解压版在 windows 环境下安装完毕;本地可通过各种客户端工具进行登录访问;如要远程访问,还需要给 root 用户配置 IP 访问权限,此处不在本文讲述内,可自行查找!

你可能感兴趣的:(数据库,mysql,windows,数据库)