【安装Mysql环境】

1.从官网下载压缩包后进行解压

官网:https://www.mysql.com/
本次文档以mysql-8.0.27-winx64.zip为例

2.在mysql根目录下配置my.ini文件

在mysql根目录下新建记事本类型即.txt文件,将以下内容复制到.txt文件中,注意将mysql安装目录换成自己的安装目录。将文件后缀从.txt改为.ini。

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录 
basedir=D:\mysql\mysql-8.0.27-winx64
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

3.将my.ini文件进行生效

在mysql根目录下搜索框上搜索cmd后按enter键打开命令行,在命令行上输入mysqld --initialize-insecure命令。

D:\software\Mysql\mysql-8.0.27-winx64>mysqld --initialize-insecure

D:\software\Mysql\mysql-8.0.27-winx64>

输入完此命令后回车等待,如果命令行没有弹出任何消息,说明执行成功,在mysql根目录下查看是否多了一个data文件夹,如果有,打开data文件夹查看文件夹内是否有内容,有则证明成功。

如果执行完mysqld --initialize-insecure命令后报错,检查cmd打开的路径是否正确,路径需要是mysql安装路径,即mysql安装包解压后的路径。
如果路径正确,检查my.ini配置文件是否正确。
可详细看cmd命令行报错提示。
例如报错为:

D:\software\Mysql\mysql-8.0.27-winx64>mysqld --initialize-insecure
mysqld: Can't create directory 'D:\software\Mysql\mysql-8.0.27-winx64\ oftware\Mysql\mysql-8.0.27-winx64\data\' (OS errno 2 - No such file or directory)
2022-09-15T07:09:34.946173Z 0 [System] [MY-013169] [Server] D:\software\Mysql\mysql-8.0.27-winx64\bin\mysqld.exe (mysqld 8.0.27) initializing of server in progress as process 13072
2022-09-15T07:09:34.946255Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file 'D:\software\Mysql\mysql-8.0.27-winx64\ oftware\Mysql\mysql-8.0.27-winx64\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2022-09-15T07:09:34.946594Z 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.
2022-09-15T07:09:34.947452Z 0 [ERROR] [MY-010187] [Server] Could not open file 'D:\software\Mysql\mysql-8.0.27-winx64\ oftware\Mysql\mysql-8.0.27-winx64\data\LAPTOP-TCV56C5M.err' for error logging: Permission denied
2022-09-15T07:09:34.948663Z 0 [ERROR] [MY-013236] [Server] The designated data directory D:\software\Mysql\mysql-8.0.27-winx64\ oftware\Mysql\mysql-8.0.27-winx64\data\ is unusable. You can remove all files that the server added to it.
2022-09-15T07:09:34.949061Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-09-15T07:09:34.949184Z 0 [System] [MY-010910] [Server] D:\software\Mysql\mysql-8.0.27-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.27)  MySQL Community Server - GPL.

经检查后发现,my.ini文件配置错误。
**注意:**在win10中配置my.ini文件时

# 设置mysql的安装目录 
basedir=D:\mysql\mysql-8.0.27-winx64

可以正确识别,但在win11中要配置为

# 设置mysql的安装目录 
basedir=D:\\mysql\mysql-8.0.27-winx64

才可正确识别。
修改完my.ini文件后,再次在命令行中执行mysqld --initialize-insecure

4.配置环境变量

在环境变量-系统变量下的path中新增安装的mysql的bin路径
如:D:\mysql\mysql-8.0.27-winx64\bin

5. 下载启动mysql服务

使用管理员身份运行cmd命令行打开mysql的bin文件夹
管理员身份运行cmd:
在这里插入图片描述
打开文件夹(根据自己的安装目录进行打开):
cd 目录 进入目录
cd… :返回上一级目录

PS C:\Users> d:
PS D:\> cd software
PS D:\software> cd Mysql
PS D:\software\Mysql> cd mysql-8.0.27-winx64
PS D:\software\Mysql\mysql-8.0.27-winx64> cd data
PS D:\software\Mysql\mysql-8.0.27-winx64\data> cd ..
PS D:\software\Mysql\mysql-8.0.27-winx64> cd bin

下载mysql服务:mysqld install mysql

PS D:\software\Mysql\mysql-8.0.27-winx64\bin> mysqld install mysql  
The service already exists!
The current server installed: D:\software\Mysql\mysql-8.0.27-winx64\bin\mysqld.exe MySQL

启动mysql服务: net start mysql,运行:mysql -uroot

PS D:\software\Mysql\mysql-8.0.27-winx64\bin> net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

PS D:\software\Mysql\mysql-8.0.27-winx64\bin> mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 MySQL Community Server - GPL

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>

出现mysql>则代表安装启动成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值