windwos10 安装Mysql8.0 2021最新傻瓜式教程

这个教程教你的是如果通过压缩包安装win10上安装Mysql,而不是installer

  • installer就是带图形界面,下载后是一个exe或者setup文件,双击运行一路next安装软件的工具
  • 压缩包就是zip后缀的

本质没有区别,installer安装后的内容和压缩包解压后的内容基本不会有区别。但是installer往往会帮你设置环境变量、修改注册表之类的工作,要完成这些额外工作,压缩包的安装方式就需要自己手动进行了。
类似JavaMysql等软件在提供installer的同时,也会提供压缩包。安装JavaMysql我推荐大家使用压缩包的方式。


实验平台:

版本    Windows 10 家庭中文版
版本号    20H2
安装日期    ‎2020/‎8/‎16
操作系统内部版本    19042.985
体验    Windows Feature Experience Pack 120.2212.2020.0

Mysql版本:

PS C:\Users\17293> mysql --version
C:\Program Files\MySQL\bin\mysql.exe  Ver 8.0.21 for Win64 on x86_64 (MySQL Community Server - GPL)

写这篇文章的初衷是因为,在win10上安装Mysql的时候,用管理员模式powershell登陆不了Mysql,直接mysql不行,mysql -u root不行,mysql -u root -p再输入mysqld --initialize生成的初始化密码不行,报的是密码正确错误ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES),太气人了!!!!!
结果阴差阳错的输入mysql -u root -p"_<AsDttMd1o2"就好了

_<AsDttMd1o2就是mysqld --initialize生成的初始密码。

下载Mysql

下载地址 https://dev.mysql.com/downloa...

下载Windows (x86, 64-bit), ZIP Archive,即体积比较小的那个

image.png

解压缩

解压缩之后放到C盘中下面的路径:
C:\Program Files\Mysql

image.png

Program Files文件夹创建一个Mysql文件夹,把解压后的文件夹切剪放到Mysql文件夹
不要放到D盘、E盘,现在是2021年,改掉把软件不装到C盘的陋习。

添加环境变量

C:\Program Files\Mysql\mysql-8.0.21-winx64\bin添加到环境变量中

注意把mysql-8.0.21-winx64换成你自己的版本

添加服务

mysqld install

添加过环境变量就需要中相对路径或者绝对路径去调用mysqld

注意是mysqld,不是mysql,因为mysql是客户端程序,mysqld是服务端程序

这个操作需要管理员权限,不然会遇到这样的错误:Install/Remove of the Service Denied!

image.png

PS C:\Windows\system32> mysqld install
Service successfully installed.

这样就成功了

配置

有些教程会教你配置my.ini,这个文件不是必须的,所以这里不讲

> cd "C:\Program Files\Mysql\mysql-8.0.21-winx64"

> mysqld.exe --initialize --console
2021-05-15T03:14:48.650104Z 0 [System] [MY-013169] [Server] C:\Program Files\Mysql\mysql-8.0.21-winx64\bin\mysqld.exe (mysqld 8.0.21) initializing of server in progress as process 6040
2021-05-15T03:14:48.689134Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-05-15T03:14:49.796361Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-05-15T03:14:51.118883Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _<AsDttMd1o2


> net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

> mysql -u root -p"_<AsDttMd1o2"
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 8
Server version: 8.0.21

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

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-8.0.21-winx64换成你自己的版本

上诉操作中有容易踩坑的地方

  • mysqld --initialize --console中的--console不可少,不然会很麻烦
  • 输入密码最好直接在-p后面,显示添加,不要少了引号,这很重要.

常见报错

    • ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
      解决办法:输入密码最好直接在-p后面,显示添加,不要少了引号,这很重要

 

登录之后,立马使用 

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
#修改加密规则 

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
#更新一下用户的密码 


ALTER user 'root'@'localhost' IDENTIFIED BY 'root';

 

修改规则和密码

 

posted @ 2022-03-07 17:20  谢牧谚  阅读(303)  评论(0编辑  收藏  举报