1. 程式人生 > 資料庫 >mysql 8.0 Windows zip包版本安裝詳細過程

mysql 8.0 Windows zip包版本安裝詳細過程

MySQL 8.0 Windows zip 安裝過程介紹,具體如下

準備:

MySQL8.0 Windows zip包下載地址。

環境:Windows 10

一、安裝

1. 解壓zip包到安裝目錄

比如我的安裝目錄是:D:\Program\MySQL

2.配置檔案

在Windows系統中,配置檔案預設是安裝目錄下的 my.ini 檔案,部分配置需要在初始安裝時配置,大部分也可以在安裝完成後進行更改。當然,極端情況下,所有的都是可以更改的。

在安裝根目錄下新增 my.ini,比如我這裡是:D:\Program\MySQL\my.ini,寫入基本配置:

[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server,else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set,remove the # and set as required.
basedir = D:\Program\MySQL
datadir = D:\DBs\MySQL
port = 3306
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed,experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

character-set-server = utf8mb4

performance_schema_max_table_instances = 600
table_definition_cache = 400
table_open_cache = 256

[mysql]
default-character-set = utf8mb4

[client]
default-character-set = utf8mb4

注意,裡面的 basedir 是我本地的安裝目錄,datadir 是我資料庫資料檔案要存放的位置,各項配置需要根據自己的環境進行配置。

檢視所有的配置項,可參考:MySQL 8.0 Reference Manual

3.初始化資料庫

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

mysqld --initialize --console

執行完成後,會列印 root 使用者的初始預設密碼,比如:

2018-04-20T02: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-04-20T02: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-04-20T02:35:01.508173Z 0 [ERROR] [MY-010340] [Server] Error message file 'D:\Program\MySQL\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-04-20T02:35:05.464644Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ
2018-04-20T02: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 目錄下執行命令:

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

參考:連結地址

三、速度測試

不用測了,官方說MySQL8比5快兩倍。

附、CentOS tar.gz 包安裝

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
shell> tar zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> ln -s mysql-8.0.11-linux-glibc2.12-x86_64 mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
shell> bin/mysqld --initialize --user=mysql
shell> bin/mysql_ssl_rsa_setup
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

參考:連結地址

精彩專題分享:mysql不同版本安裝教程 mysql5.7各版本安裝教程 mysql5.6各版本安裝教程

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。