windows 10 安装MySQL 8.4.5

一. 下载

https://dev.mysql.com/downloads/mysql/

选择需要的版本下载,我下的图中所示版本,windows系统是 8.4.5 LTS

二 解压

我的解压目录是:D:\soft\install\db\mysql-8.4.5-winx64

三 配置环境变量

 四 初始化配置表

在解压目录 D:\soft\install\db\mysql-8.4.5-winx64 下新建my.ini文件,内容如下,该内容copy到my.ini中保存即可

 

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录,注意:有的人目录用单斜杠会报错
basedir=D:\\soft\\install\\db\\mysql-8.4.5-winx64
# 设置mysql数据库的数据的存放目录,注意:有的人目录用单斜杠会报错,且初始操作前不能有data目录,初始化时会新建
datadir=D:\\soft\\install\\db\\mysql-8.4.5-winx64\\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证,注意:MySQL 8.4.5实测,加该配置会初始化失败,原因是高版本该插件已弃用
#mysql_native_password
#default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4

五 初始化

开始菜单-右键-管理员运行 Windows PowerShell(管理员)

登入安装目录bin目录下

PS C:\Users\ADMIN> cd D:\soft\install\db\mysql-8.4.5-winx64
PS D:\soft\install\db\mysql-8.4.5-winx64> cd bin

 

初始化

PS D:\soft\install\db\mysql-8.4.5-winx64\bin> .\mysqld --initialize --console
2025-07-11T15:53:21.419963Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2025-07-11T15:53:21.425639Z 0 [System] [MY-013169] [Server] D:\soft\install\db\mysql-8.4.5-winx64\bin\mysqld.exe (mysqld 8.4.5) initializing of server in progress as process 7128
2025-07-11T15:53:21.443832Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-07-11T15:53:21.685100Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-07-11T15:53:23.473181Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _&fdw40A!+(A
2025-07-11T15:53:25.163319Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.

 

安装数据库

PS D:\soft\install\db\mysql-8.4.5-winx64\bin> .\mysqld --install
Service successfully installed.

 

首次登录

PS D:\soft\install\db\mysql-8.4.5-winx64\bin> .\mysql -u root -p
Enter password: ************   //注意此处的密码为前面标红的,执行初始化命令.\mysqld --initialize --console时生成的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.5

Copyright (c) 2000, 2025, 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' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)

 

创建普通用户

mysql> CREATE USER 'liuwei'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)

 

给新用户赋权

mysql> GRANT ALL PRIVILEGES ON *.* TO 'liuwei'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'liuwei'@'%';
Query OK, 0 rows affected (0.00 sec)

 

查看新用户权限

mysql> show grants for 'liuwei'@'%';
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 登出

mysql> exit
Bye
PS D:\soft\install\db\mysql-8.4.5-winx64\bin>

 

切换新用户登录

PS D:\soft\install\db\mysql-8.4.5-winx64\bin> .\mysql -u liuwei -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.4.5 MySQL Community Server - GPL

Copyright (c) 2000, 2025, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)

 

使用数据库

mysql> use mysql
Database changed

 

可以开始建表增删改查。。

 

posted @ 2025-07-12 00:33  苏沐、  阅读(167)  评论(0)    收藏  举报