MySQL5.70安裝過程及發現問題解決方案


1、如何安裝?html


一、【運行】->【cmd】打開小黑窗口。定位到MySQL安裝目錄【個人D:\Program Files\mysql-5.7.9-winx64】的bin目錄下,輸入【mysqld -install】。以下圖,表示安裝成功mysql



二、打開MySQL安裝目錄,找到【my-default.ini】,配置一些簡單的信息。sql

# These are commonly set, remove the # and set as required.
basedir = D:\Program Files\mysql-5.7.9-winx64
datadir = D:\Program Files\mysql-5.7.9-winx64\data
port = 3306
# server_id = .....


三、輸入【mysqld --initialize】,爲MySQL進行初始化。初始化過程可能須要持續一會,當出現以下界面,且在MySQL安裝目錄中的data文件夾有內容時,表示成功初始化了。數據庫


若是略去該步驟,在嘗試經過命令【mysqld --console】追蹤錯誤信息時會出現以下錯誤。因爲新版本的MySQL在啓動時須要初始化一寫表。所以,請不要省略此步驟ide

D:\Program Files\mysql-5.7.9-winx64\bin><span style="color:#ff6666;"><strong>mysqld --console</strong></span>
mysqld: Can't change dir to 'D:\Program Files\mysql-5.7.9-winx64\data\' (Errcode
: 2 - No such file or directory)
2015-12-18T08:54:25.263539Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
 deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2015-12-18T08:54:25.263539Z 0 [Warning] Insecure configuration for --secure-file
-priv: Current value does not restrict location of generated files. Consider set
ting it to a valid, non-empty path.
2015-12-18T08:54:25.263539Z 0 [Note] mysqld (mysqld 5.7.9) starting as process 6
3944 ...
2015-12-18T08:54:25.265539Z 0 [Warning] <span style="color:#ff6666;">Can't create test file D:\Program Files\
mysql-5.7.9-winx64\data\Richard-PC.lower-test</span>
2015-12-18T08:54:25.265539Z 0 [Warning]<span style="color:#ff6666;"> Can't create test file D:\Program Files\
mysql-5.7.9-winx64\data\Richard-PC.lower-test</span>
2015-12-18T08:54:25.266539Z 0 [ERROR] failed to set datadir to <span style="color:#ff6666;">D:\Program Files\
mysql-5.7.9-winx64\data\</span>
2015-12-18T08:54:25.266539Z 0 [ERROR] Aborting

2015-12-18T08:54:25.266539Z 0 [Note] Binlog end
2015-12-18T08:54:25.267539Z 0 [Note] mysqld: Shutdown complete


四、輸入【mysqld -install】安裝MySQL服務。具體啓動過程略。測試


2、沒法運行?

在成功啓動MySQL後,經過鏈接MySQL數據庫出現以下錯誤ui

1045- access denied for user 'root'@'localhost' using password yes

按照網上的方式,結合本身的實操經驗,總結以下解決辦法this

一、首先輸入【mysqld  --skip-grant-tables】,這條命令是做用了跳過認證直接進入(啓動)MySQL。spa


二、嘗試 輸入【update user set password=PASSWORD('123456') where user='root';】。嘗試修改Root密碼爲123456。rest

可能出現的錯誤。所以,此步驟不可解決問題。

ERROR 1054 (42S22): Unknown column 'password' in 'field list'


三、嘗試輸入【GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant option;】

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables opt
ion so it cannot execute this statement

若是出現上述錯誤,請輸入下面紅色標註的命令,設置可讀屬性
mysql> <span style="color:#ff6666;">set global read_only=1;</span>
Query OK, 0 rows affected (0.00 sec)

mysql> <span style="color:#ff6666;">flush privileges;</span>
Query OK, 0 rows affected (0.00 sec)


而後在輸入【GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant option;】
出現以下錯誤。

mysql> GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant o
ption;
ERROR 1131 (42000): You are using MySQL as an anonymous user and anonymous users
 are not allowed to change passwords
所以,不可直接對root帳戶進行密碼的修改。此步驟也不可行。


四、第三步不可行的時候,可嘗試換種思路解決。從新創建一個管理員權限的帳戶,(我這邊用的時richard,按需修改)

mysql> GRANT ALL ON *.* to '<span style="color:#ff6666;">richard</span>'@'localhost' IDENTIFIED BY '11111' with gran
t option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

而後重啓MySQL數據庫,用新建的管理員帳戶【richard】登陸。

鏈接成功




五、用【richard】帳戶登陸,併爲root帳戶修改密碼。

GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant option;
flush privileges;


六、測試root帳戶鏈接成功,問題解決!