基于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,為了方便查看日志,建議增加參數
增加參數后時間顯示,方便閱讀。