windows同時安裝 5.7 8.0 mysql

飞蚊發表於2024-09-10

電腦配置升級了,想著自己電腦本地安裝資料庫,重新學習一下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%*nz

    2020-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 0 [Note] Shutting down slave threads
    2020-01-06T12:36:28.763943Z 0 [Note] Forcefully disconnecting 0 remaining clients
    2020-01-06T12:36:28.772298Z 0 [Note] Event Scheduler: Purging the queue. 0 events
    2020-01-06T12:36:28.775985Z 0 [Note] Binlog end
    2020-01-06T12:36:28.779654Z 0 [Note] Shutting down plugin 'ngram'
    2020-01-06T12:36:28.779782Z 0 [Note] Shutting down plugin 'partition'
    2020-01-06T12:36:28.780434Z 0 [Note] Shutting down plugin 'BLACKHOLE'
    2020-01-06T12:36:28.780889Z 0 [Note] Shutting down plugin 'ARCHIVE'
    2020-01-06T12:36:28.781495Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
    2020-01-06T12:36:28.782033Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
    2020-01-06T12:36:28.782711Z 0 [Note] Shutting down plugin 'MyISAM'
    2020-01-06T12:36:28.783141Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
    2020-01-06T12:36:28.783563Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
    2020-01-06T12:36:28.784021Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
    2020-01-06T12:36:28.784406Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
    2020-01-06T12:36:28.787567Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
    2020-01-06T12:36:28.794063Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
    2020-01-06T12:36:28.794995Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
    2020-01-06T12:36:28.795741Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
    2020-01-06T12:36:28.796564Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
    2020-01-06T12:36:28.797016Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
    2020-01-06T12:36:28.797522Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
    2020-01-06T12:36:28.798010Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
    2020-01-06T12:36:28.798490Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
    2020-01-06T12:36:28.798970Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
    2020-01-06T12:36:28.799438Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
    2020-01-06T12:36:28.799871Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
    2020-01-06T12:36:28.800360Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
    2020-01-06T12:36:28.804643Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
    2020-01-06T12:36:28.804719Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
    2020-01-06T12:36:28.811108Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
    2020-01-06T12:36:28.813588Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
    2020-01-06T12:36:28.815982Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
    2020-01-06T12:36:28.824638Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
    2020-01-06T12:36:28.825589Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
    2020-01-06T12:36:28.834224Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
    2020-01-06T12:36:28.837309Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
    2020-01-06T12:36:28.838494Z 0 [Note] Shutting down plugin 'INNODB_CMP'
    2020-01-06T12:36:28.838905Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
    2020-01-06T12:36:28.839309Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
    2020-01-06T12:36:28.839723Z 0 [Note] Shutting down plugin 'INNODB_TRX'
    2020-01-06T12:36:28.840115Z 0 [Note] Shutting down plugin 'InnoDB'
    2020-01-06T12:36:28.840561Z 0 [Note] InnoDB: FTS optimize thread exiting.
    2020-01-06T12:36:28.841021Z 0 [Note] InnoDB: Starting shutdown...
    2020-01-06T12:36:28.957313Z 0 [Note] InnoDB: Dumping buffer pool(s) to D:\Program\mysql\mysql-5.7.24-winx64\data\ib_buffer_pool
    2020-01-06T12:36:28.962702Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 200106 20:36:28
    2020-01-06T12:36:29.731460Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2591524
    2020-01-06T12:36:29.732301Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
    2020-01-06T12:36:29.739414Z 0 [Note] Shutting down plugin 'MEMORY'
    2020-01-06T12:36:29.739625Z 0 [Note] Shutting down plugin 'CSV'
    2020-01-06T12:36:29.739704Z 0 [Note] Shutting down plugin 'sha256_password'
    2020-01-06T12:36:29.739775Z 0 [Note] Shutting down plugin 'mysql_native_password'
    2020-01-06T12:36:29.739990Z 0 [Note] Shutting down plugin 'binlog'
    2020-01-06T12:36:29.741858Z 0 [Note] D:\Program\mysql\mysql-5.7.24-winx64\bin\mysqld.exe: Shutdown complete
    

二.安裝8.0版本

(1)在解壓目錄建立配置檔案 - my.ini

[mysqld]
# set basedir to your installation path
basedir=D:/Program/mysql/mysql-8.0.18-winx64
# set datadir to the location of your data directory
datadir=D:/Program/mysql/mysql-8.0.18-winx64/data
# 多個MySQL時,修改port,換個埠號
port = 13306

(2)建立data資料夾,初始化資料目錄:注意有兩種選項

  • --initialize:預設的安全安裝模式,會生成隨機初始的root密碼,這種情況下,密碼被標記為過期,第一次登陸進去後需要設定新的密碼
  • --initialize-insecure:不安全的安裝模式,不會root生成密碼,預設為空密碼
  • --user:指定使用者
  • 參考官網的文件 - 2.10.1 Initializing the Data Directory
## 初始化資料目錄,使用第二種方初始化自動建立data資料夾
PS D:\Program\mysql\mysql-8.0.18-winx64\bin> .\mysqld --initialize-insecure --user=hecg95

(3)首次啟動:

## 啟動MySQL
PS D:\Program\mysql\mysql-8.0.18-winx64\bin> .\mysqld --console
2020-01-06T12:58:00.798580Z 0 [System] [MY-010116] [Server] D:\Program\mysql\mysql-8.0.18-winx64\bin\mysqld.exe (mysqld 8.0.18) starting as process 33124
2020-01-06T12:58:01.573236Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-01-06T12:58:01.604355Z 0 [System] [MY-010931] [Server] D:\Program\mysql\mysql-8.0.18-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.18'  socket: ''  port: 13306  MySQL Community Server - GPL.
2020-01-06T12:58:01.618988Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060

(4)初次登陸及修改密碼:

  • 檢視data目錄下的hqiogwdt0114.err檔案:提示目前使用預設的空密碼

    2020-01-06T12:51:51.897459Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
  啟動8.0 服務
  mysqld install MySQL80 --defaults-file="D:\DevelopTool\MySQL\mysql-5.7.42\my.ini"
  開啟服務(管理員開啟的cmd視窗開啟服務)
  mysqld --install mysql88 --defaults-file="E:\mysql-8.0.39-winx64\mysql-8.0.39-winx64\my.ini"
  • 使用空密碼登陸MySQL,重新設定新的密碼:

    在MySQL 8.0中,預設的身份驗證外掛已從更改 mysql_native_password為 caching_sha2_password,並且 'root'@'localhost'管理帳戶caching_sha2_password預設使用。

    PS D:\Program\mysql\mysql-8.0.18-winx64\bin> .\mysql -P 13306  -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 9
    Server version: 8.0.18 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2019, 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
    Database changed
    
    ## 注意此處不同於之前的版本
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
    Query OK, 0 rows affected (0.01 sec)
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)
    
    ## 否則客戶端連線會報錯
    1251 - Client does not support authentication protocol requested by server; consider upgrading MySQL client
    
  • 使用mysqladmin關閉和重新啟動MySQL:

    ## 關閉MySQL
    PS D:\Program\mysql\mysql-8.0.18-winx64\bin> .\mysqladmin -P 13306 -u root shutdown -p
    Enter password: ******
    
    ## 監聽到關閉訊號
    2020-01-06T13:21:31.470768Z 15 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.18).
    2020-01-06T13:21:31.473233Z 0 [System] [MY-013105] [Server] D:\Program\mysql\mysql-8.0.18-winx64\bin\mysqld.exe: Normal shutdown.
    2020-01-06T13:21:31.766555Z 0 [System] [MY-010910] [Server] D:\Program\mysql\mysql-8.0.18-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.18)  MySQL Community Server - GPL.
    
    ## 重新啟動 --console 會輸出日誌
    PS D:\Program\mysql\mysql-8.0.18-winx64\bin> .\mysqld --console
    2020-01-06T13:23:27.071931Z 0 [System] [MY-010116] [Server] D:\Program\mysql\mysql-8.0.18-winx64\bin\mysqld.exe (mysqld 8.0.18) starting as process 24388
    2020-01-06T13:23:27.696975Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
    2020-01-06T13:23:27.732170Z 0 [System] [MY-010931] [Server] D:\Program\mysql\mysql-8.0.18-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.18'  socket: ''  port: 13306  MySQL Community Server - GPL.
    2020-01-06T13:23:27.862052Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060

相關文章