win11安装MySQL8.0.32记录
一、下载MySQL
二、将压缩包解压至安装目录
三、配置环境变量
四、新建my.ini文件
[mysqld]
# 设置3306端口
port=3306
# 自定义设置mysql的安装目录,即解压mysql压缩包的目录
basedir=D:\Program Files\MySQL\mysql-8.0.32-winx64
# 自定义设置mysql数据库的数据存放目录
datadir=D:\Program Files\MySQL\mysql-8.0.32-winx64\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数,这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTFMB4
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口和默认字符集
port=3306
default-character-set=utf8mb4
参数名称 | 说明 |
---|---|
port | 表示 MySQL 服务器的端口号。 |
basedir | 表示 MySQL 的安装路径。 |
datadir | 表示 MySQL 数据文件的存储位置,也是数据表的存放位置。 |
max_connections | 表示允许同时访问MySQL服务器的最大连接数,其中一个连接是保留的,留给管理员专用的。 |
max_connect_errors | 表示允许连接失败的次数,这是为了防止有人从该主机试图攻击数据库系统。 |
default-character-set | 表示服务器端默认的字符集。 |
default-storage-engine | 创建数据表时,默认使用的存储引擎。 |
default_authentication_plugin | 默认使用“mysql_native_password”插件认证,而非caching_sha2_password。 |
五、安装MySQL
5.1 以管理员身份打开命令提示符
5.2 安装MySQL
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysqld -install
Service successfully installed.
5.3 初始化
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysqld --initialize --console
2024-01-29T07:23:03.421213Z 0 [System] [MY-013169] [Server] D:\Program Files\MySQL\mysql-8.0.32-winx64\bin\mysqld.exe (mysqld 8.0.32) initializing of server in progress as process 10788
2024-01-29T07:23:03.422541Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2024-01-29T07:23:03.445955Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-01-29T07:23:03.877003Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-01-29T07:23:04.766645Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: O**********C
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysqld --install
The service already exists!
The current server installed: "D:\Program Files\MySQL\mysql-8.0.32-winx64\bin\mysqld" MySQL
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysqld --initialize-insecure
5.4 启动mysql
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysql -uroot -p
Enter password: ************
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
5.5 重置数据库密码
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysql -uroot -p
Enter password: ************(此处为初始化产生的密码)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.32
Copyright (c) 2000, 2023, 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 by 'password' password expire never;
Query OK, 0 rows affected (0.02 sec)
mysql> alter user root@localhost identified with mysql_native_password by '********';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>mysql -uroot -p********
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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
5.6 查看本机IP地址
D:\Program Files\MySQL\mysql-8.0.32-winx64\bin>ipconfig/all
无线局域网适配器 本地连接* 10:
连接特定的 DNS 后缀 . . . . . . . :
描述. . . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #2
物理地址. . . . . . . . . . . . . : **-**-**-**-**-**
DHCP 已启用 . . . . . . . . . . . : 否
自动配置已启用. . . . . . . . . . : 是
本地链接 IPv6 地址. . . . . . . . : ****::****:****:****:****%12(首选)
IPv4 地址 . . . . . . . . . . . . : ***.***.***.**(首选)
子网掩码 . . . . . . . . . . . . : ***.***.***.*
默认网关. . . . . . . . . . . . . :
TCPIP 上的 NetBIOS . . . . . . . : 已启用