我的環境
- MySQL-8.0.17
- Windows 10
MySQL8.0.17 下載地址
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.17-winx64.zip
安裝步驟
初始化Mysql
解壓,使用CMD命名進入解壓後的bin目錄執行初始化命令:mysqld --initialize --console
初始化完畢後,會生成密碼,我生成的密碼是yIqn;h&cq4vu
D:\>cd Tools
D:\Tools>cd Mysql-8.0.17-winx64
D:\Tools\Mysql-8.0.17-winx64>cd bin
D:\Tools\Mysql-8.0.17-winx64\bin>mysqld --initialize --console
2019-09-19T18:54:29.151678Z 0 [System] [MY-013169] [Server]
D:\Tools\Mysql-8.0.17-winx64\bin\mysqld.exe (mysqld 8.0.17) initializing of server
in progress as process 16776 2019-09-19T18:55:14.709870Z 5 [Note] [MY-010454] [Server]
A temporary password is generated for root@localhost: yIqn;h&cq4vu
2019-09-19T18:55:49.626651Z 0 [System] [MY-013170] [Server]
D:\Tools\Mysql-8.0.17-winx64\bin\mysqld.exe (mysqld 8.0.17) initializing of server has completed
安裝服務
輸入安裝服務命令:mysqld install MySQL-8.0.17
輸入啓動服務器命令:net start mysql-8.0.17
D:\Tools\Mysql-8.0.17-winx64\bin>mysqld install MySQL-8.0.17
Service successfully installed.
D:\Tools\Mysql-8.0.17-winx64\bin>net start mysql-8.0.17
MySQL-8.0.17 服務正在啓動 ...
MySQL-8.0.17 服務已經啓動成功。
修改密碼
使用初始化生成密碼進行首次登陸,並修改密碼。
D:\Tools\Mysql-8.0.17-winx64\bin>mysql -uroot -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17
Copyright (c) 2000, 2019, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.45 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Query OK, 0 rows affected (0.41 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
mysql> quit
Bye
D:\Tools\Mysql-8.0.17-winx64\bin>mysql -uroot -ppassword
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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> quit
Bye
安裝配置完成過程
D:\>cd Tools
D:\Tools>cd Mysql-8.0.17-winx64
D:\Tools\Mysql-8.0.17-winx64>cd bin
D:\Tools\Mysql-8.0.17-winx64\bin>mysqld --initialize --console
2019-09-19T18:54:29.151678Z 0 [System] [MY-013169] [Server] D:\Tools\Mysql-8.0.17-winx64\bin\mysqld.exe (mysqld 8.0.17) initializing of server in progress as process 16776
2019-09-19T18:55:14.709870Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: yIqn;h&cq4vu
2019-09-19T18:55:49.626651Z 0 [System] [MY-013170] [Server] D:\Tools\Mysql-8.0.17-winx64\bin\mysqld.exe (mysqld 8.0.17) initializing of server has completed
D:\Tools\Mysql-8.0.17-winx64\bin>mysqld install MySQL-8.0.17
Service successfully installed.
D:\Tools\Mysql-8.0.17-winx64\bin>net start mysql-8.0.17
MySQL-8.0.17 服務正在啓動 ...
MySQL-8.0.17 服務已經啓動成功。
D:\Tools\Mysql-8.0.17-winx64\bin>mysql -uroot -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17
Copyright (c) 2000, 2019, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.45 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Query OK, 0 rows affected (0.41 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
mysql> quit
Bye
D:\Tools\Mysql-8.0.17-winx64\bin>mysql -uroot -ppassword
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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> quit
Bye
常見問題
1.sqlyog工具連接報錯
具體錯誤信息:plugin caching_sha2_password could not be loaded
解決方案:
修改密碼規則
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘password’ PASSWORD EXPIRE NEVER;
修改密碼
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
更新權限
FLUSH PRIVILEGES;
依次輸入即可解決
2.連接雲服務器mysql數據庫
連接雲服務器的數據庫需要:
1.防火牆設置
2.安全組配置
3.允許root賬戶遠程訪問
MySQL爲了安全考慮,默認只能localhost使用root訪問。通過以下的命令,可以使其他的ip也可以使用root帳號訪問,但是不建議這樣做。
D:\Tools\Mysql-8.0.17-winx64\bin>mysql -uroot -ppassword
mysql> use mysql
Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.60 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.10 sec)
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
4.初始化MySQL後密碼登錄失敗原因
錯誤提示:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
照成的原因:
1.數據庫未啓動
2.密碼錯誤
3.通過新創建的服務啓動mysql,但是啓動的是機器上老的mysql導致這種情況發生
我一直習慣使用MySQl免安裝版本,這樣與系統的耦合度小,更換系統時不需要重新安裝,創建服務就是能繼續使用了。爲了方便使用mysql的命令,我MySQL的bin目錄配置到path系統變量上了,這時更換新版本數據庫,初始化完畢安裝服務並啓動,輸入初始化的密碼,死活就是登錄失敗。後來看了下服務的屬性,居然指向老版本mysqld命令,也就是,啓動的還是老版本的數據庫,而我這邊一直使用初始化的密碼登錄,肯定是錯誤的。刪除服務,刪除path系統變量配置的mysql路徑。重新生成服務啓動輸入密碼,認證通過。唉,裏裏外外搞了幾個小時。各種辦法都試了。。
5.Can not perform keyring migration : Invalid --keyring-migration-source option.
使用命令出錯,把mysql命令敲成mysqld進行登錄報錯。
6.無法啓動程序,因爲計算機中丟失MSVCP140.dll
下載安裝vc++ 2015環境即可
下載地址
https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe