mysql-8.0.12-winx64安裝教程(安裝包的教程)
目錄
安裝環境
win10
下載zip安裝包
進入頁面,點選底部"No thanks, just start my download."。開始下載。
環境配置
解壓zip包到安裝目錄
我的解壓在C:\software\tools\mysql-8.0.12-winx64
配置環境變數
其中MYSQL_HOME=C:\software\tools\mysql-8.0.12-winx64
配置初始化的my.ini檔案
我們發現解壓後的目錄並沒有my.ini檔案,沒關係可以自行建立。在安裝根目錄下新增 my.ini(新建文字檔案,將檔案型別改為.ini),寫入基本配置:
-
[mysqld]
-
#設定埠號
-
port=3306
-
#設定mysql的安裝目錄
-
#切記此處一定要用雙斜槓\\
-
basedir=C:\\software\\tools\\mysql-8.0.12-winx64
-
#設定mysql資料庫的資料存放目錄
-
datadir=C:\\software\\tools\\mysql-8.0.12-winx64\\data
-
#允許最大連線數
-
max_connections=200
-
#允許連線失敗的次數。這是為了防止有人從該主機試圖攻擊資料庫系統
-
max_connect_errors=10
-
# 服務端使用的字符集預設為UTF8
-
character-set-server=utf8
-
# 建立新表時將使用的預設儲存引擎
-
default-storage-engine=INNODB
-
# 預設使用“mysql_native_password”外掛認證
-
default_authentication_plugin=mysql_native_password
-
[mysql]
-
# 設定mysql客戶端預設字符集
-
default-character-set=utf8
-
[client]
-
# 設定mysql客戶端連線服務端時預設使用的埠
-
port=3306
-
default-character-set=utf8
放入根目錄中。
安裝
初始化資料庫
在安裝時,必須以管理員身份執行cmd,否則在安裝時會報錯,會導致安裝失敗的情況。
在MySQL安裝目錄的 bin 目錄下執行命令:
mysqld --initialize --console
執行完成後,會列印 root 使用者的初始預設密碼,比如:
-
C:\Windows\system32>cd C:\software\tools\mysql-8.0.12-winx64\bin
-
C:\software\tools\mysql-8.0.12-winx64\bin>mysqld --initialize --console
-
2018-08-23T13:56:18.046640Z 0 [System] [MY-013169] [Server] C:\software\tools\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as process 11180
-
2018-08-23T13:56:23.403547Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: 07+e+Cj.Us0P
-
2018-08-23T13:56:25.952809Z 0 [System] [MY-013170] [Server] C:\software\tools\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server has completed
其中,初始密碼為:07+e+Cj.Us0P。
安裝服務
在MySQL安裝目錄的 bin 目錄下執行命令:
mysqld --install [服務名]
後面的服務名可以不寫,預設的名字為 mysql。當然,如果你的電腦上需要安裝多個MySQL服務,就可以用不同的名字區分了,比如 mysql5 和 mysql8。
安裝完成之後,就可以通過命令net start mysql啟動MySQL的服務了。通過命令net stop mysql停止服務。通過命令sc delete MYSQL/mysqld -remove解除安裝MYSQL服務。
-
C:\software\tools\mysql-8.0.12-winx64\bin>net start mysql
-
mysql 服務正在啟動 .
-
mysql 服務已經啟動成功。
更改密碼
在MySQL安裝目錄的 bin 目錄下執行命令:
mysql -u root -p
這時候會提示輸入密碼,記住了上面安裝時的初始密碼,填入即可登入成功,進入MySQL命令模式。
-
C:\software\tools\mysql-8.0.12-winx64\bin>mysql -uroot -p
-
Enter password: ************
-
Welcome to the MySQL monitor. Commands end with ; or \g.
-
Your MySQL connection id is 10
-
Server version: 8.0.12
-
Copyright (c) 2000, 2018, 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 with mysql_native_password by 'root';
-
Query OK, 0 rows affected (0.10 sec)
-
mysql> exit;
-
Bye
-
C:\software\tools\mysql-8.0.12-winx64\bin>mysql -uroot -proot
-
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 11
-
Server version: 8.0.12 MySQL Community Server - GPL
-
Copyright (c) 2000, 2018, 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中執行命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密碼';
修改密碼,注意命令尾的;一定要有 ; 這是mysql的語法。
配置遠端登陸
管理員root的host是localhost,代表僅限localhost登入訪問。如果要允許開放其他ip登入,則需要新增新的host。如果要允許所有ip訪問,可以直接修改成“%”。
建立使用者:
CREATE USER 'hadoop'@'%' IDENTIFIED WITH mysql_native_password BY 'hadoop';
#(需要注意:mysql8.0加密方式修改了) #檢查使用者
-
mysql> select user, host, plugin, authentication_string from user;
-
+------------------+-----------+-----------------------+------------------------------------------------------------------------+
-
| user | host | plugin | authentication_string |
-
+------------------+-----------+-----------------------+------------------------------------------------------------------------+
-
| hadoop | % | mysql_native_password | *B34D36DA2C3ADBCCB80926618B9507F5689964B6 |
-
| mysql.infoschema | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
-
| mysql.session | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
-
| mysql.sys | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
-
| root | localhost | mysql_native_password | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
-
+------------------+-----------+-----------------------+------------------------------------------------------------------------+
授權遠端資料庫
#授權所有許可權
GRANT ALL PRIVILEGES ON *.* TO 'hadoop'@'%';
#授權基本的查詢修改許可權,按需求設定
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'hadoop'@'%';
檢視使用者許可權
show grants for 'hadoop'@'%';
-
mysql> show grants for 'hadoop'@'%';
-
+------------------------------------+
-
| Grants for [email protected]% |
-
+------------------------------------+
-
| GRANT USAGE ON *.* TO `hadoop`@`%` |
-
+------------------------------------+
-
1 row in set (0.00 sec)
結束!