Windows安裝Mysql

1.下載相應的安裝包

從官方網站可以找到兩種文件包,一種是exe安裝程序,這種的基本下一步下一步就OK了,但是在沒有網絡的狀態下我並沒有成功,另一種是zip壓縮包。這次我下載的是ZIP壓縮包,我選擇的是8.0.11版本。
下載地址:https://downloads.mysql.com/archives/community/
在這裏插入圖片描述

2.解壓進行配置

將該zip包解壓到相應的目錄下新建my.ini文件,相關內容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
 
[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 = C:\Mysql8.0.11
 datadir = C:\Mysql8.0.11\data
 port = 3306
server_id = 1
 
 
# 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

3.進行初始化命令

以管理員身份運行cmd,進入到mysql安裝目錄的bin下,執行命令:mysqld --defaults-file=C:\Mysql8.0.11\my.ini --initialize --console
在這裏插入圖片描述
注意:將紅框內的密碼記錄下來(AIRlFkiEb7_B)臨時密碼,後續用於登陸修改密碼。
注:可能會遇到這個錯誤
在這裏插入圖片描述
解決:windows系統缺少vc++2015,則需要下載安裝vc_redist
在這裏插入圖片描述
在這裏插入圖片描述

4.創建服務

還是在bin目錄下執行mysqld install MySQLXLM --defaults-file="C:\Mysql8.0.11\my.ini"
在這裏插入圖片描述
MySQLXLM爲服務名,出現Service successfully installed.說明創建已成功

5.測試連接

使用win+r打開compmgmt.msc管理
找到MySQLXLM(自定義服務名)啓動
在這裏插入圖片描述

啓動後使用navicat連接
在這裏插入圖片描述
輸入臨時密碼連接會出現1251錯誤,原因是MySQL8.0版本的加密方式和MySQL5.0的不一樣,連接會報錯。

6.修改密碼

還是在bin目錄下執行mysql -uroot -p -P3306(3306爲my.ini文件中自定義的端口)後輸入之前記錄的臨時密碼登錄。
修改密碼:alter user root@localhost identified by 'password' password expire never;
再次輸入:alter user root@localhost identified with mysql_native_password by 'root';
在這裏插入圖片描述
其中by後面的爲修改後的密碼,最後再輸入flush privileges;
在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章