Windows10安裝MySQL5.7

環境

操作系統:windows10 專業增強版
MySQL:mysql-5.7.24-winx64 下載鏈接

安裝步驟

下載MySQL

選擇合適的操作系統版本下載MySQL安裝包並解壓放置到合適的路徑下,例如E:\MySQL路徑下
解壓路徑

配置系統環境變量

Created with Raphaël 2.2.0此電腦右擊“屬性”"高級系統設置" "環境變量"在 "用戶變量"欄新增MySQL變量和值在"用戶變量"欄修改"Path"的值關閉

新增MYSQL變量
MYSQL變量
修改Path變量值
Path變量

安裝MySQL

  1. 右擊開始菜單按鈕,選擇“命令提示符(管理員)”選項。
  2. 進入MySQL安裝包跟目錄的bin路徑下,如圖所示,執行安裝命令mysqld -install
    安裝MySQL

配置my.ini文件

注意: 安裝包裏面如果沒有my.ini文件,需要自己在MySQL安裝路徑的根目錄下創建
my.ini文件內容如下:

[client]

# pipe=

# socket=MYSQL
default-character-set=utf8  
port=3306

[mysql]
no-beep

default-character-set=utf8


# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
# server_type=3
[mysqld]

# The next three options are mutually exclusive to SERVER_PORT below.
# skip-networking
# enable-named-pipe
# shared-memory

# shared-memory-base-name=MYSQL

# The Pipe the MySQL Server will use
# socket=MYSQL

# The TCP/IP Port the MySQL Server will listen on
port=3306

# Path to installation directory. All paths are usually resolved relative to this.
basedir=E:/MySQL/mysql-5.7.24-winx64

# Path to the database root


# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# General and Slow logging.
log-output=FILE

general-log=0

general_log_file="mysql57.log"

slow-query-log=1

slow_query_log_file="mysql57-slow.log"

long_query_time=10

# Binary Logging.
# log-bin

# Error Logging.
log-error="mysql57.err"

# Server Id.
server-id=1

# Specifies the on how table names are stored in the metadata.
# If set to 0, will throw an error on case-insensitive operative systems
# If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive.
# If set to 2, table names are stored as given but compared in lowercase.
# This option also applies to database names and table aliases.
lower_case_table_names=1

# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=151

說明

  1. 編碼改爲utf8

[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

  1. 注意log-error的值(mysql57.err),下面步驟中需要從中獲取登錄的初始密碼

初始化MySQL

在剛纔的“命令提示符”中,執行mysqld --initialize

啓動MySQL

執行net start mysql
初始化並啓動

進入MySQL

  1. 進入安裝跟目錄的data路徑中,找到mysql57.err文件,打開搜索A temporary password is generated for root@localhost:緊跟在後面的就是初始密碼(oGkoF:sQe9lf)
    data路徑
    初始密碼
  2. 執行命令mysql -uroot -p輸入上面的初始密碼登錄
  • 修改root用戶密碼 ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
    修改用戶密碼
  • 查看是否爲utf8編碼 show variables like 'character%';
    查看編碼
  • root用戶授權 GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
    授權
  • 刷新退出 flush privileges; exit!
    注意事項
    1、徹底刪除MySQL, 參考
    2、utf8_general_ci和utf8_unicode_ci區別 參考
    3、一定要以"管理員模式"打開"命令提示符"

參考鏈接

1、https://blog.csdn.net/yulutian/article/details/78971369
2、https://www.jianshu.com/p/710e5861c198

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