windows安装mysql

最近重装了系统,mysql没了,在官网找了半天才找到下载,这里是为了记录一下

1、官网下载

官网地址:https://www.mysql.com/
下载地址:https://dev.mysql.com/downloads/mysql/

  1. 用官网地址一步一步的走(直接选下载地址就可以直接下载了,这里为了记录下官网找下载的步骤)
    在这里插入图片描述

  2. 选了downloads往下滑
    在这里插入图片描述
    在这里插入图片描述

  3. 选择版本下载

    现在最新8.0.28了,更新真快
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    这是从8.0.27开始了
    在这里插入图片描述
    一般选择上边的就可以,下边的是(ZIP存档、调试二进制文件和测试套件)
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    这不就有了压缩包了么
    在这里插入图片描述
    解压完成之后是这样的
    在这里插入图片描述

2、安装mysql

解压完成之后修改环境变量,这里是为了能方便的启动mysql服务

  1. 打开bin文件夹
    在这里插入图片描述
  2. 复制文件路径
    在这里插入图片描述
  3. 右击此电脑,选择属性
    在这里插入图片描述
  4. 选择高级系统变量

在这里插入图片描述

  1. 选择环境变量
    在这里插入图片描述
  2. 选择path,编辑

在这里插入图片描述

  1. 新建,粘贴bin路径

在这里插入图片描述
环境变量就配置完了

  • 新建my.ini文件(新建一个txt文本,将名字改成my.ini,注意这里后缀名要显示出来)

在这里插入图片描述

  • 显示扩展名

在这里插入图片描述

  • 修改文件名

在这里插入图片描述

  • 写配置文件
[mysqld]
basedir=D:\database\mysql-5.7.36-winx64\
datadir=D:\database\mysql-5.7.36-winx64\data\
port=3306
skip-grant-tables

在这里插入图片描述

  • 启动管理员模式下的CMD,并将路径切换至mysql下的bin目录,然后输入mysqld –install (安装mysql)
		PS D:\database\mysql-5.7.36-winx64\bin> mysqld install
		Service successfully installed.
  • 再输入 mysqld --initialize-insecure --user=mysql 初始化数据文件
PS D:\database\mysql-5.7.36-winx64\bin> mysqld --initialize-insecure --user=mysql
  • 然后再次启动mysql 然后用命令 mysql –u root –p 进入mysql管理界面(密码可为空)(可能报错)
PS D:\database\mysql-5.7.36-winx64\bin> mysql -u root -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
  • 右击计算机点管理,找到mysql,启动服务

在这里插入图片描述
在这里插入图片描述
这里的密码不用输入,直接回车就好了

PS D:\database\mysql-5.7.36-winx64\bin> mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36 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.

修改密码

mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

刷新权限

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

然后注释my.ini中的skip-grant-tables,保存
在这里插入图片描述
再次进入要输密码了

mysql> exit
Bye
PS D:\database\mysql-5.7.36-winx64\bin> mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.36 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> exit
Bye

Navicat连接也可以
在这里插入图片描述

3、再安装一个mysql

为啥要再安一个呢?---->安着玩儿

复制一遍mysql
在这里插入图片描述
修改my.ini,这里主要修改地址和端口,要把最后一行注释了
在这里插入图片描述

删了data文件夹,不然一会配置的时候报错
在这里插入图片描述
执行命令(mysqld --defaults-file=D:\database\mysql-5.7.36-winx64-3308\my.ini --initialize --console)【初始化mysql】
这是没有删data报的错,玩儿砸了吧,快把data删了

PS D:\database\mysql-5.7.36-winx64-3308> mysqld --defaults-file=D:\database\mysql-5.7.36-winx64-3308\my.ini --initialize --console
2022-01-27T03:39:19.769556Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-01-27T03:39:19.771566Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2022-01-27T03:39:19.772176Z 0 [ERROR] Aborting

删了data再执行命令,就会在最后生成一个密码【初始化mysql服务】

PS D:\database\mysql-5.7.36-winx64-3308> mysqld --defaults-file=D:\database\mysql-5.7.36-winx64-3308\my.ini --initialize --console
2022-01-27T03:39:51.853809Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-01-27T03:39:52.857642Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-01-27T03:39:53.153086Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-01-27T03:39:53.344641Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c9d5106d-7f22-11ec-8ace-00ff90375768.
2022-01-27T03:39:53.397144Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-01-27T03:39:54.337720Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-01-27T03:39:54.338004Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-01-27T03:39:54.338872Z 0 [Warning] CA certificate ca.pem is self signed.
2022-01-27T03:39:55.049808Z 1 [Note] A temporary password is generated for root@localhost: &d:CrO#hU4Y.
PS D:\database\mysql-5.7.36-winx64-3308>

安装mysql服务:MySQL3308

PS D:\database\mysql-5.7.36-winx64-3308> mysqld install MySQL3308 --defaults-file="D:\database\mysql-5.7.36-winx64-3308\my.ini"
Service successfully installed.

启动MySQL3308

PS D:\database\mysql-5.7.36-winx64-3308> net start MySQL3308
MySQL3308 服务正在启动 .
MySQL3308 服务已经启动成功。
PS D:\database\mysql-5.7.36-winx64-3308> mysql -u root -p --protocol=tcp --host=localhost --port=3308 #这里的启动方式是通过端口号启动
Enter password: ******  #这里的密码是上边随机生成的那个
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.36

再次设置密码

mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

这里可能用update更新报错:
在这里插入图片描述
那就用这个:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

再次启动输入新密码

PS D:\database\mysql-5.7.36-winx64-3308> mysql -u root -p --protocol=tcp --host=localhost --port=3308
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.36

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吧!

4、连接报错

在这里插入图片描述
执行下边几个语句就好了
在这里插入图片描述

USE mysql;
UPDATE `user` SET `host` = '%' WHERE `user` = 'root';
FLUSH PRIVILEGES;

未完待续······

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Azure++

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值