在 windows 上,使用 noinstall ZIP Archives 安装

  1. 初始化数据路径

    1. Windows (x86, 64-bit), ZIP Archive 下载地址 https://dev.mysql.com/downloads/mysql/ 解压ZIP Archive到 D:\mysql-9.2.0-winx64.zip 文件夹下,重命名这文件夹为msql.如果操作系统内置了对ZIP文件的解压,则下载后不需要解压. 然后,可以看到 D:\msql 文件夹下有 bin 文件夹. 确保以管理员,进入 CMD D:\msql\bin 下,输入 mysqld --initialize --console
      D:\msql\bin>mysqld --initialize --console
      2023-01-17T16:39:32.642735Z 0 [System] [MY-013169] [Server] D:\a\bin\mysqld.exe
      (mysqld 8.0.31) initializing of server in progress as process 13160
      2023-01-17T16:39:32.735877Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
      2023-01-17T16:39:38.267508Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
      2023-01-17T16:39:41.883513Z 6 [Note] [MY-010454] [Server] A temporary password is generated
      for root@localhost: QhbqNnBTf9+a
      
      D:\msql\bin>
                                                     
      从上面最后一行,可以看到:QhbqNnBTf9+a 是随机产生的root用户下的密码.

  2. 安装服务及修改密码

    1. 安装 MySQL server:在CMD D:\msql\bin 下,输入 mysqld --install
      D:\msql\bin>mysqld --install
      Service successfully installed.
                                      
      开启 MySQL server:在CMD D:\msql\bin 下,输入 net start mysql
      D:\msql\bin>net start mysql
      MySQL 服务正在启动 ..
      MySQL 服务已经启动成功。
      
      D:\msql\bin>
                                      
      登录服务: 先输入 mysql -uroot -p 然后输入密码. QhbqNnBTf9+a
      D:\msql\bin>mysql -uroot -p
      Enter password: ************
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 9
      Server version: 8.0.31-cluster MySQL Cluster Community Server - GPL
      
      Copyright (c) 2000, 2022, 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>
                                            

    2. 修改 mysql root 账户密码:使用命令:
      alter user 'root'@'localhost' identified by 'happy';
      mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'happy';
      Query OK, 0 rows affected (0.03 sec)
      
      mysql>
                                      
      这样,初始数据路径时随机产生的密码 QhbqNnBTf9+a 被修改为 happy。 可以输入 quit 退出服务。以新密码 happy 登录服务:
      先输入 mysql -uroot -p 然后输入密码.
      D:\msql\bin>mysql -uroot -p
      Enter password: *****
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 9
      Server version: 8.0.31-cluster MySQL Cluster Community Server - GPL
      
      Copyright (c) 2000, 2022, 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>
                                          
      停止服务: net stop mysql
      删除服务: sc delete mysql

    3. 前面讲的,都是在CMD D:\msql>目录下登录或操作的. 如果在命令行其它目录登录呢?这时电脑不能识别,原因是, 没有设置环境变量。 右建点击"开始"->"系统"->"高级系统设置" 新建系统变量名 MYSQL_HOME 变量名 D:\msql 在系统变量里,找到Path变量,点击“编辑”按钮,%MYSQL_HOME%\bin添加到path变量的值. 正确设置环境变量后,CMD中任何目录下都能成功登录mysql服务。