在 windows 上,使用 noinstall ZIP Archives 安装
初始化数据路径
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用户下的密码.
安装服务及修改密码
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>
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 登录服务:
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