windows安装mysql
1. 下载
-
url
https://dev.mysql.com/downloads/mysql/ -
下载
2. 安装|启动
解压缩
将下载后的文件解压缩到 E:\opt\ 下,生成 mysql-8.0.29-winx64 目录
初始化数据库
- 打开cmd,进入mysql目录下的bin目录:
C:\Users\Administrator>e:
E:\opt>cd mysql-8.0.29-winx64\bin
- 初始化数据库
E:\opt\mysql-8.0.29-winx64\bin>mysqld --initialize --console
2022-06-06T15:04:41.229440Z 0 [System] [MY-013169] [Server] E:\opt\mysql-8.0.29-winx64\bin\mysqld.exe (mysqld 8.0.29) initializing of server in progress as process 12228
2022-06-06T15:04:41.373478Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-06-06T15:04:47.991509Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-06-06T15:04:59.857361Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: I&C:,e7Qb>1a
如上图可见,自动生成的mysql密码为
I&C:,e7Qb>1a
安装mysql服务
E:\opt\mysql-8.0.29-winx64\bin>mysqld -install
Service successfully installed.
启动mysql
E:\opt\mysql-8.0.29-winx64\bin>sc start mysql
SERVICE_NAME: mysql
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x3
WAIT_HINT : 0x3a98
PID : 17136
FLAGS :
3. 修改密码/密码规则
如果不修改密码规则,navicat报错:Authentication plugin ‘caching_sha2_password’ cannot be loaded
- 登录数据库
E:\opt\mysql-8.0.29-winx64\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.29
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> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.09 sec)
- 修改加密规则和密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxxx';
Query OK, 0 rows affected (0.09 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.05 sec)
- 结果