基于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.40Copyright (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 - GPLCopyright (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,为了方便查看日志,建议增加参数
增加参数后时间显示,方便阅读。