1. 程式人生 > >MySQL5.70安裝過程及發現問題解決方案

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

一、如何安裝?

1、【執行】->【cmd】開啟小黑視窗。定位到MySQL安裝目錄【我的D:\Program Files\mysql-5.7.9-winx64】的bin目錄下,輸入【mysqld -install】。如下圖,表示安裝成功


2、開啟MySQL安裝目錄,找到【my-default.ini】,配置一些簡單的資訊。

# 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 = .....

3、輸入【mysqld --initialize】,為MySQL進行初始化。初始化過程可能需要持續一會,當出現如下介面,且在MySQL安裝目錄中的data資料夾有內容時,表示成功初始化了。


如果略去該步驟,在嘗試通過命令【mysqld --console】追蹤錯誤資訊時會出現如下錯誤。由於新版本的MySQL在啟動時需要初始化一寫表。因此,請不要省略此步驟

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

4、輸入【mysqld -install】安裝MySQL服務。具體啟動過程略。

二、無法執行?

在成功啟動MySQL後,通過連線MySQL資料庫出現如下錯誤

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

按照網上的方式,結合自己的實操經驗,總結如下解決辦法

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

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

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

ERROR 1054 (42S22): Unknown column 'password' in 'field list'
3、嘗試輸入【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賬戶進行密碼的修改。此步驟也不可行。

4、第三步不可行的時候,可嘗試換種思路解決。重新建立一個管理員許可權的賬戶,(我這邊用的時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】登入。

連線成功




5、用【richard】賬戶登入,併為root賬戶修改密碼。

GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant option;
flush privileges;
6、測試root賬戶連線成功,問題解決!