1. 程式人生 > >mysql-8.0.12-winx64安裝教程(安裝包的教程)

mysql-8.0.12-winx64安裝教程(安裝包的教程)

目錄

安裝環境

環境配置

安裝

安裝服務

更改密碼

安裝環境

win10

下載zip安裝包

進入頁面,點選底部"No thanks, just start my download."。開始下載。mysql下載

環境配置

解壓zip包到安裝目錄

我的解壓在C:\software\tools\mysql-8.0.12-winx64

mysql目錄結構

配置環境變數

環境變數

其中MYSQL_HOME=C:\software\tools\mysql-8.0.12-winx64

配置初始化的my.ini檔案

我們發現解壓後的目錄並沒有my.ini檔案,沒關係可以自行建立。在安裝根目錄下新增 my.ini(新建文字檔案,將檔案型別改為.ini),寫入基本配置:

  1. [mysqld]

  2. #設定埠號

  3. port=3306

  4. #設定mysql的安裝目錄

  5. #切記此處一定要用雙斜槓\\

  6. basedir=C:\\software\\tools\\mysql-8.0.12-winx64

  7. #設定mysql資料庫的資料存放目錄

  8. datadir=C:\\software\\tools\\mysql-8.0.12-winx64\\data

  9. #允許最大連線數

  10. max_connections=200

  11. #允許連線失敗的次數。這是為了防止有人從該主機試圖攻擊資料庫系統

  12. max_connect_errors=10

  13. # 服務端使用的字符集預設為UTF8

  14. character-set-server=utf8

  15. # 建立新表時將使用的預設儲存引擎

  16. default-storage-engine=INNODB

  17. # 預設使用“mysql_native_password”外掛認證

  18. default_authentication_plugin=mysql_native_password

  19. [mysql]

  20. # 設定mysql客戶端預設字符集

  21. default-character-set=utf8

  22. [client]

  23. # 設定mysql客戶端連線服務端時預設使用的埠

  24. port=3306

  25. default-character-set=utf8

放入根目錄中。

安裝

初始化資料庫

在安裝時,必須以管理員身份執行cmd,否則在安裝時會報錯,會導致安裝失敗的情況。

以管理員身份執行cmd

在MySQL安裝目錄的 bin 目錄下執行命令:

mysqld --initialize --console

執行完成後,會列印 root 使用者的初始預設密碼,比如:

  1. C:\Windows\system32>cd C:\software\tools\mysql-8.0.12-winx64\bin

  2. C:\software\tools\mysql-8.0.12-winx64\bin>mysqld --initialize --console

  3. 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

  4. 2018-08-23T13:56:23.403547Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: 07+e+Cj.Us0P

  5. 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服務。

  1. C:\software\tools\mysql-8.0.12-winx64\bin>net start mysql

  2. mysql 服務正在啟動 .

  3. mysql 服務已經啟動成功。

工作管理員

更改密碼

在MySQL安裝目錄的 bin 目錄下執行命令:

mysql -u root -p

這時候會提示輸入密碼,記住了上面安裝時的初始密碼,填入即可登入成功,進入MySQL命令模式。

  1. C:\software\tools\mysql-8.0.12-winx64\bin>mysql -uroot -p

  2. Enter password: ************

  3. Welcome to the MySQL monitor. Commands end with ; or \g.

  4. Your MySQL connection id is 10

  5. Server version: 8.0.12

  6. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

  7. Oracle is a registered trademark of Oracle Corporation and/or its

  8. affiliates. Other names may be trademarks of their respective

  9. owners.

  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  11. mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'root';

  12. Query OK, 0 rows affected (0.10 sec)

  13. mysql> exit;

  14. Bye

  15. C:\software\tools\mysql-8.0.12-winx64\bin>mysql -uroot -proot

  16. mysql: [Warning] Using a password on the command line interface can be insecure.

  17. Welcome to the MySQL monitor. Commands end with ; or \g.

  18. Your MySQL connection id is 11

  19. Server version: 8.0.12 MySQL Community Server - GPL

  20. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

  21. Oracle is a registered trademark of Oracle Corporation and/or its

  22. affiliates. Other names may be trademarks of their respective

  23. owners.

  24. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  25. 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加密方式修改了) #檢查使用者

  1. mysql> select user, host, plugin, authentication_string from user;

  2. +------------------+-----------+-----------------------+------------------------------------------------------------------------+

  3. | user | host | plugin | authentication_string |

  4. +------------------+-----------+-----------------------+------------------------------------------------------------------------+

  5. | hadoop | % | mysql_native_password | *B34D36DA2C3ADBCCB80926618B9507F5689964B6 |

  6. | mysql.infoschema | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

  7. | mysql.session | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

  8. | mysql.sys | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

  9. | root | localhost | mysql_native_password | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

  10. +------------------+-----------+-----------------------+------------------------------------------------------------------------+

授權遠端資料庫

#授權所有許可權 

GRANT ALL PRIVILEGES ON *.* TO 'hadoop'@'%';

#授權基本的查詢修改許可權,按需求設定

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'hadoop'@'%';

檢視使用者許可權

show grants for 'hadoop'@'%';
  1. mysql> show grants for 'hadoop'@'%';

  2. +------------------------------------+

  3. | Grants for [email protected]% |

  4. +------------------------------------+

  5. | GRANT USAGE ON *.* TO `hadoop`@`%` |

  6. +------------------------------------+

  7. 1 row in set (0.00 sec)

結束!