基于windows安装MySQL8.0.40

基于windows安装MySQL8.0.40

基于windows 安装 MySQL8.0.40,解压文件到D:\mysql-8.0.40-winx64

在D:\mysql-8.0.40-winx64目录下创建my.ini文件,并更新一下内容

复制代码
[client]    #客户端设置,即客户端默认的连接参数
# 设置mysql客户端连接服务端时默认使用的端口
port=3380
 
#默认编码
default-character-set = utf8mb4
 
[mysql]    #客户端设置
#MySQL 提示符配置
#用户名@主机名+mysql版本号+数据库名
prompt=\\u@\\h \\v [\\d]>\\_
 
# 设置mysql客户端默认字符集
default-character-set = utf8mb4
 
[mysqld]    #服务端基本设置
# 默认连接端口
port=3380
 
# MySQL安装根目录的路径
basedir=D:\mysql-8.0.40-winx64
 
# MySQL服务器数据目录的路径
datadir=D:\mysql-8.0.40-winx64\data
 
# 允许最大连接数
max_connections=200
 
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
 
#服务端默认编码
character_set_server = utf8mb4
 
#在创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
 
# 配置时区
default-time_zone='+8:00'
log_timestamps=system

D:\mysql-8.0.40-winx64\bin>mysqld --install "MySQL8" --defaults-file="D:\mysql-8.0.40-winx64\my.ini"
Service successfully installed.

D:\mysql-8.0.40-winx64\bin>mysqld --initialize --console
2025-05-05T00:08:04.457934Z 0 [System] [MY-013169] [Server] D:\mysql-8.0.40-winx64\bin\mysqld.exe (mysqld 8.0.40) initializing of server in progress as process 19256
2025-05-05T00:08:04.553388Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-05-05T00:08:14.305429Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-05-05T00:08:30.185901Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: #y%7*wTmus;,

D:\mysql-8.0.40-winx64\bin>net start mysql8
MySQL8 服务正在启动 ...
MySQL8 服务已经启动成功。


D:\mysql-8.0.40-winx64\bin>

修改默认密码

复制代码
D:\mysql-8.0.40-winx64\bin>mysql -uroot -p -P3380
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.40

Copyright (c) 2000, 2024, 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.

root@localhost 8.0.40 [(none)]> use mysql;
No connection. Trying to reconnect...
Connection id:    10
Current database: *** NONE ***

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
root@localhost 8.0.40 [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.07 sec)

root@localhost 8.0.40 [(none)]> flush privileges;
Query OK, 0 rows affected (0.03 sec)

root@localhost 8.0.40 [(none)]>

测试验证:锁定用户对于已经建立的连接无影响。

test01用户未锁定之前登录数据库并执行操作

复制代码
D:\mysql-8.0.40-winx64\bin>mysql -utest01 -ptest01 -P3380
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 21
Server version: 8.0.40 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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.

test01@localhost 8.0.40 [(none)]> use mysql;
Database changed
test01@localhost 8.0.40 [mysql]> select user,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
| test01           | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

接下来锁定用户

复制代码
alter user 'test01'@'localhost'  account lock;

再尝试原来的窗口执行命令,正常执行

复制代码
test01@localhost 8.0.40 [mysql]> select user,host,account_lock from user;
ERROR 1054 (42S22): Unknown column 'account_lock' in 'field list'
test01@localhost 8.0.40 [mysql]> select user,host,account_locked from user;
+------------------+-----------+----------------+
| user             | host      | account_locked |
+------------------+-----------+----------------+
| mysql.infoschema | localhost | Y              |
| mysql.session    | localhost | Y              |
| mysql.sys        | localhost | Y              |
| root             | localhost | N              |
| test01           | localhost | Y              |
+------------------+-----------+----------------+
5 rows in set (0.00 sec)

test01@localhost 8.0.40 [mysql]> select user,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
| test01           | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

test01@localhost 8.0.40 [mysql]>

尝试创建新的连接,失败,提示

复制代码
ERROR 3118 (HY000): Access denied for user 'test01'@'localhost'. Account is locked.

同理,设置密码过期对已经建立的连接无影响。

复制代码
test01@localhost 8.0.40 [mysql]> select user,host,account_lock from user;
ERROR 1054 (42S22): Unknown column 'account_lock' in 'field list'
test01@localhost 8.0.40 [mysql]> select user,host,account_locked,password_expired from user;
+------------------+-----------+----------------+------------------+
| user             | host      | account_locked | password_expired |
+------------------+-----------+----------------+------------------+
| mysql.infoschema | localhost | Y              | N                |
| mysql.session    | localhost | Y              | N                |
| mysql.sys        | localhost | Y              | N                |
| root             | localhost | N              | N                |
| test01           | localhost | N              | **Y**                |
+------------------+-----------+----------------+------------------+
5 rows in set (0.00 sec)

test01@localhost 8.0.40 [mysql]> select user,host,account_lock from user;
ERROR 1054 (42S22): Unknown column 'account_lock' in 'field list'
test01@localhost 8.0.40 [mysql]> select user,host,account_locked from user;
+------------------+-----------+----------------+
| user             | host      | account_locked |
+------------------+-----------+----------------+
| mysql.infoschema | localhost | Y              |
| mysql.session    | localhost | Y              |
| mysql.sys        | localhost | Y              |
| root             | localhost | N              |
| test01           | localhost | N              |
+------------------+-----------+----------------+
5 rows in set (0.00 sec)

刚开始配置my.ini文件中,没有指定时区,查看err日志文件的时候发现时间是UTC,为了方便查看日志,建议增加参数

增加参数后时间显示,方便阅读。

相关推荐
gAlAxy...16 分钟前
SpringMVC 响应数据和结果视图:从环境搭建到实战全解析
大数据·数据库·mysql
b***46241 小时前
从 SQL 语句到数据库操作
数据库·sql·oracle
CryptoPP1 小时前
使用 KLineChart 这个轻量级的前端图表库
服务器·开发语言·前端·windows·后端·golang
vx_dmxq2112 小时前
【微信小程序学习交流平台】(免费领源码+演示录像)|可做计算机毕设Java、Python、PHP、小程序APP、C#、爬虫大数据、单片机、文案
java·spring boot·python·mysql·微信小程序·小程序·idea
m***92382 小时前
【SQL】MySQL中的字符串处理函数:concat 函数拼接字符串,COALESCE函数处理NULL字符串
数据库·sql·mysql
r***93482 小时前
CentOS7安装Mysql5.7(ARM64架构)
adb·架构
TracyCoder1233 小时前
MySQL 实战宝典(八):Java后端MySQL分库分表工具解析与选型秘籍
java·开发语言·mysql
P***84394 小时前
解决Spring Boot中Druid连接池“discard long time none received connection“警告
spring boot·后端·oracle
字节拾光录5 小时前
手机号存储避坑指南:从20亿级数据库实践看,为什么VARCHAR才是终极答案
java·数据库·oracle
p***924810 小时前
深入理解与实战SQL IFNULL()函数
数据库·sql·oracle