電腦配置升級了,想著自己電腦本地安裝資料庫,重新學習一下MySQL,下面記錄了本地Windows安裝兩個版本MySQL的過程。
一.安裝5.7版本
(1)在解壓目錄建立配置檔案 - my.ini
[mysqld]
# set basedir to your installation path
basedir=D:/Program/mysql/mysql-5.7.24-winx64
# set datadir to the location of your data directory
datadir=D:/Program/mysql/mysql-5.7.24-winx64/data
(2)建立data
資料夾,初始化資料目錄:注意有兩種選項
- --initialize:預設的安全安裝模式,會生成隨機初始的root密碼,這種情況下,密碼被標記為過期,第一次登陸進去後需要設定新的密碼
- --initialize-insecure:不安全的安裝模式,不會root生成密碼
- --user:指定使用者
## 初始化資料目錄,使用第一種方式
PS D:\Program\mysql\mysql-5.7.24-winx64\bin> .\mysqld --initialize --user=hecg95
(3)首次啟動:
## 啟動MySQL
PS D:\Program\mysql\mysql-5.7.24-winx64\bin> .\mysqld --console
...
2020-01-06T12:06:55.258100Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2020-01-06T12:06:55.258762Z 0 [Note] InnoDB: Uses event mutexes
2020-01-06T12:06:55.259034Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier
2020-01-06T12:06:55.259223Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-01-06T12:06:55.259652Z 0 [Note] InnoDB: Number of pools: 1
2020-01-06T12:06:55.259933Z 0 [Note] InnoDB: Not using CPU crc32 instructions
2020-01-06T12:06:55.263195Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2020-01-06T12:06:55.268347Z 0 [Note] InnoDB: Completed initialization of buffer pool
2020-01-06T12:06:55.313150Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2020-01-06T12:06:55.366453Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-01-06T12:06:55.367217Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2020-01-06T12:06:55.415184Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB.
2020-01-06T12:06:55.422146Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2020-01-06T12:06:55.422578Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2020-01-06T12:06:55.423030Z 0 [Note] InnoDB: Waiting for purge to start
2020-01-06T12:06:55.484660Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 2591440
2020-01-06T12:06:55.485287Z 0 [Note] Plugin 'FEDERATED' is disabled.
2020-01-06T12:06:55.485644Z 0 [Note] InnoDB: Loading buffer pool(s) from D:\Program\mysql\mysql-5.7.24-winx64\data\ib_buffer_pool
2020-01-06T12:06:55.495151Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2020-01-06T12:06:55.497758Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2020-01-06T12:06:55.498298Z 0 [Note] IPv6 is available.
2020-01-06T12:06:55.499141Z 0 [Note] - '::' resolves to '::';
2020-01-06T12:06:55.499488Z 0 [Note] Server socket created on IP: '::'.
2020-01-06T12:06:55.503746Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200106 20:06:55
2020-01-06T12:06:55.540602Z 0 [Note] Event Scheduler: Loaded 0 events
2020-01-06T12:06:55.541097Z 0 [Note] D:\Program\mysql\mysql-5.7.24-winx64\bin\mysqld.exe: ready for connections.
Version: '5.7.24' socket: '' port: 3306 MySQL Community Server (GPL)
(4)查詢密碼及修改密碼:
-
隨機密碼在
data
目錄下的hqiogwdt0114.err
檔案中:wD2q)XQF%*nz2020-01-06T12:04:46.034179Z 1 [Note] A temporary password is generated for root@localhost: wD2q)XQF%*nz
-
使用初始密碼登陸MySQL,重新設定新的密碼:
PS D:\Program\mysql\mysql-5.7.24-winx64\bin> .\mysql -u root -p Enter password: ************ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.24 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 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> use mysql ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. ## 首次登陸,提示需要修改密碼 mysql> set password="123456"; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye PS D:\Program\mysql\mysql-5.7.24-winx64\bin>
-
使用
mysqladmin
關閉和重新啟動MySQL:PS D:\Program\mysql\mysql-5.7.24-winx64\bin> .\mysqladmin -u root shutdown mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)' ## 需要密碼 PS D:\Program\mysql\mysql-5.7.24-winx64\bin> .\mysqladmin -u root shutdown -p Enter password: ****** ## 重新啟動 --console 會輸出日誌 PS D:\Program\mysql\mysql-5.7.24-winx64\bin> .\mysqld --console ... 2020-01-06T12:36:09.767463Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2020-01-06T12:36:09.767981Z 0 [Note] InnoDB: Uses event mutexes 2020-01-06T12:36:09.768364Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2020-01-06T12:36:09.776583Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2020-01-06T12:36:09.779705Z 0 [Note] InnoDB: Number of pools: 1 2020-01-06T12:36:09.780609Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2020-01-06T12:36:09.784180Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2020-01-06T12:36:09.789972Z 0 [Note] InnoDB: Completed initialization of buffer pool 2020-01-06T12:36:09.840754Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2020-01-06T12:36:09.896882Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2020-01-06T12:36:09.897805Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2020-01-06T12:36:09.938564Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB. 2020-01-06T12:36:09.953197Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2020-01-06T12:36:09.953663Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2020-01-06T12:36:09.957244Z 0 [Note] InnoDB: Waiting for purge to start 2020-01-06T12:36:10.010316Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 2591496 2020-01-06T12:36:10.012857Z 0 [Note] Plugin 'FEDERATED' is disabled. 2020-01-06T12:36:10.014410Z 0 [Note] InnoDB: Loading buffer pool(s) from D:\Program\mysql\mysql-5.7.24-winx64\data\ib_buffer_pool 2020-01-06T12:36:10.030225Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key 2020-01-06T12:36:10.033015Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 2020-01-06T12:36:10.037653Z 0 [Note] IPv6 is available. 2020-01-06T12:36:10.038029Z 0 [Note] - '::' resolves to '::'; 2020-01-06T12:36:10.039131Z 0 [Note] Server socket created on IP: '::'. 2020-01-06T12:36:10.045001Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200106 20:36:10 2020-01-06T12:36:10.076855Z 0 [Note] Event Scheduler: Loaded 0 events 2020-01-06T12:36:10.077455Z 0 [Note] D:\Program\mysql\mysql-5.7.24-winx64\bin\mysqld.exe: ready for connections. Version: '5.7.24' socket: '' port: 3306 MySQL Community Server (GPL) ## 監聽到關閉訊號 2020-01-06T12:36:28.761907Z 0 [Note] D:\Program\mysql\mysql-5.7.24-winx64\bin\mysqld.exe: Normal shutdown 2020-01-06T12:36:28.762424Z 0 [Note] Giving 0 client threads a chance to die gracefully 2020-01-06T12:36:28.763869Z