电脑配置升级了,想着自己电脑本地安装数据库,重新学习一下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