MySQL 5.7.17 for WIN8安裝初探

chenfeng發表於2017-03-08
1. 下載MySQL Community Server 5.7.17,注意選擇系統型別(32位/64位)



2. 解壓縮MySQL壓縮包到指定目錄:



3.新增環境變數
右鍵-->我的電腦-->屬性--> 高階系統設定-->環境變數
新建系統變數:
變數名:MYSQL_HOME
變數值:D:\database\mysql-5.7.17-winx64

再在path末尾中新增 %MYSQL_HOME%\bin
例如:
D:\Python27;C:\Users\duansf\Desktop\vim\vim80;%MYSQL_HOME%\bin

4.註冊為windows系統服務:
需要在命令提示符(管理員模式)下執行:

d:\database\mysql-5.7.17-winx64\bin>d:\database\mysql-5.7.17-winx64\bin\mysqld install MySQL --defaults-file="d:\database\mysql-5.7.17-winx64\my.ini"
Service successfully installed.


my.ini內容如下:
[mysql]
# 設定mysql客戶端預設字符集
default-character-set=utf8 
[mysqld]
#設定3306埠
port = 3306 
# 設定mysql的安裝目錄
basedir=D:/database/mysql-5.7.17-winx64
# 設定mysql資料庫的資料的存放目錄
datadir=D:/database/mysql-5.7.17-winx64/data
slow_query_log=TRUE
slow_query_log_file=d:/slow_query_log.txt
long_query_time=1
# 允許最大連線數
max_connections=200
# 服務端使用的字符集預設為8位元編碼的latin1字符集
character-set-server=utf8
# 建立新表時將使用的預設儲存引擎
default-storage-engine=INNODB 
# 主從複製引數配置
log_bin = mysql-bin
server_id = 1


5.手動啟動MySQL服務:
d:\database\mysql-5.7.17-winx64\bin>net start mysql
MySQL 服務正在啟動 ..
MySQL 服務無法啟動。

服務沒有報告任何錯誤。


請鍵入 NET HELPMSG 3534 以獲得更多的幫助。




手動啟動服務失敗,經檢視官方資料,解決思路如下:
啟動前我們需要使用-initialize初始化Data目錄生成並生成隨機密碼,使用-initialize-insecure可以生成空密碼。預設帳號root

此處我們用-initialize-insecure生成空密碼


d:\database\mysql-5.7.17-winx64\bin>mysqld --initialize-insecure

d:\database\mysql-5.7.17-winx64\bin>net start mysql
MySQL 服務正在啟動 ..
MySQL 服務已經啟動成功。

用空密碼登入:
C:\Users\duansf>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17-log MySQL Community Server (GPL)


Copyright (c) 2000, 2016, 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>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)


mysql>


6.更改root密碼:
mysql> UPDATE mysql.user SET password=PASSWORD("123456") WHERE user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql>


更改密碼報錯,因為新版5.7版本的mysql資料庫下的user表中已經沒有Password欄位了,而是將加密後的使用者密碼儲存於authentication_string欄位
更改密碼命令如下:

mysql> update MySQL.user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 1


mysql>
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.13 sec)

7.用新密碼登入:
d:\database\mysql-5.7.17-winx64\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17-log MySQL Community Server (GPL)


Copyright (c) 2000, 2016, 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>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2134955/,如需轉載,請註明出處,否則將追究法律責任。

相關文章