windows10+mysql8.0.11zip安裝


准備:

MySQL8.0 Windows zip包下載地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip

環境:Windows 10

一、安裝

1. 解壓zip包到安裝目錄

我的安裝目錄是D:\Program Files\mysql-8.0.11-winx64

2.配置文件

windows系統中配置文件默認是安裝目錄下的 my.ini 文件,部分配置需要在初始安裝時配置,大部分也可以在安裝完成后進行更改,不知道別人是什么情況,我的是該文件目錄下不存在my.ini文件,所以我新建了該文件,如下

 

 寫入基本配置如下:

 1 [mysqld]
 2 default_authentication_plugin=mysql_native_password
 3 # Remove leading # and set to the amount of RAM for the most important data
 4 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
 5 # innodb_buffer_pool_size = 128M
 6 
 7 # Remove leading # to turn on a very important data integrity option: logging
 8 # changes to the binary log between backups.
 9 # log_bin
10 
11 # These are commonly set, remove the # and set as required.
12 basedir=D:\Program Files\mysql-8.0.11-winx64
13 datadir=D:\Program Files\mysql-8.0.11-winx64\data(這兩行是主要修改的內容,會自動生成data文件夾,其他直接粘貼即可) 14 port = 3306
15 # server_id = .....
16 
17 
18 # Remove leading # to set options mainly useful for reporting servers.
19 # The server defaults are faster for transactions and fast SELECTs.
20 # Adjust sizes as needed, experiment to find the optimal values.
21 # join_buffer_size = 128M
22 # sort_buffer_size = 2M
23 # read_rnd_buffer_size = 2M 
24 
25 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
26 
27 character-set-server = utf8mb4
28 
29 performance_schema_max_table_instances = 600
30 table_definition_cache = 400
31 table_open_cache = 256
32 
33 [mysql]
34 default-character-set = utf8mb4
35 
36 [client]
37 default-character-set = utf8mb4

注意,里面的 basedir 是我本地的安裝目錄,datadir 是我數據庫數據文件要存放的位置,各項配置需要根據自己的環境進行配置。

 

3.初始化數據庫

在MySQL安裝目錄的 bin 目錄下執行命令:

.\mysqld --initialize --console

執行完成后,會打印 root 用戶的初始默認密碼,比如:

2018-05-01T14:35:01.507037Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-05-01T14:35:01.507640Z 0 [System] [MY-013169] [Server] D:\Program\MySQL8\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 11064 2018-05-01T14:35:01.508173Z 0 [ERROR] [MY-010340] [Server] Error message file 'D:\Program Files\mysql-8.0.11-winx64\share\english\errmsg.sys' had only 1090 error messages, but it should contain at least 4512 error messages. Check that the above file is the right version for this program! 2018-05-01T14:35:05.464644Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ 2018-05-01T14:35:07.017280Z 0 [System] [MY-013170] [Server] D:\Program\MySQL8\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed

其中,第4行的“APWCY5ws&hjQ”就是初始密碼,在沒有更改密碼前,需要記住這個密碼,后續登錄需要用到。

要是你手賤,關快了,或者沒記住,那也沒事,刪掉初始化的 datadir 目錄,再執行一遍初始化命令,又會重新生成的。當然,也可以使用安全工具,強制改密碼,用什么方法,自己隨意。

 

4.安裝服務

在MySQL安裝目錄的 bin 目錄下執行命令:

.\mysqld --install [服務名]

后面的服務名可以不寫,默認的名字為 mysql。當然,如果你的電腦上需要安裝多個MySQL服務,就可以用不同的名字區分了,比如 mysql5 和 mysql8。

安裝完成之后,就可以通過命令net start mysql啟動MySQL的服務了。 

二.更改密碼和密碼認證插件

在MySQL安裝目錄的 bin 目錄下執行命令:

 net start mysql

.\mysql -uroot -p

這時候會提示輸入密碼,記住了第3步的密碼,填入即可登錄成功,進入MySQL命令模式

在MySQL8.0.4以前,執行

SET PASSWORD=PASSWORD('[修改的密碼]');

就可以更改密碼,但是MySQL8.0.4開始,這樣默認是不行的。因為之前,MySQL的密碼認證插件是“mysql_native_password”,而現在使用的是“caching_sha2_password”。

因為當前有很多數據庫工具和鏈接包都不支持“caching_sha2_password”,為了方便,我暫時還是改回了“mysql_native_password”認證插件。

在MySQL中執行命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';(注意一定要有分號)(注意一定要有分號)

修改密碼驗證插件,同時修改密碼。

如果想默認使用“mysql_native_password”插件認證,可以在配置文件中配置default_authentication_plugin項。

[mysqld] default_authentication_plugin=mysql_native_password

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM