基于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,为了方便查看日志,建议增加参数

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

相关推荐
fen_fen2 小时前
用户信息表建表及批量插入 100 条数据(MySQL/Oracle)
数据库·mysql·oracle
玉梅小洋10 小时前
Windows 10 Android 构建配置指南
android·windows
雨中风华17 小时前
Linux, macOS系统实现远程目录访问(等同于windows平台xFsRedir软件的目录重定向)
linux·windows·macos
·云扬·17 小时前
MySQL 8.0 Redo Log 归档与禁用实战指南
android·数据库·mysql
IT邦德17 小时前
Oracle 26ai DataGuard 搭建(RAC到单机)
数据库·oracle
筵陌18 小时前
MySQL索引及其底层原理(上)
mysql
怣5019 小时前
MySQL子查询零基础入门教程:从小白到上手(零基础入门版)
数据库·mysql
yuuki23323319 小时前
【C++】继承
开发语言·c++·windows
非凡ghost19 小时前
PowerDirector安卓版(威力导演安卓版)
android·windows·学习·软件需求
猫头虎20 小时前
基于信创openEuler系统安装部署OpenTeleDB开源数据库的实战教程
数据库·redis·sql·mysql·开源·nosql·database