1. 程式人生 > >Windows系統安裝MySQL-8.0.12

Windows系統安裝MySQL-8.0.12


layout: post
title: “Windows系統安裝MySQL-8.0.12”
description: Windows系統安裝MySQL-8.0.12
category: 資料庫

本文介紹的是MySQL-8.0.12 windows安裝

下載

官網 或者 百度網盤

安裝

下載完成,將檔案解壓到你想要安裝的盤裡。這裡我安裝到了D盤。之後以管理員身份執行DOS視窗。
進入到mysql的bin資料夾

D:\mysql-8.0.12-winx64\bin>

my.ini

  • 在mysql-8.0.12-winx64的資料夾下建立一個名為data的空資料夾。
  • bin目錄中建立一個my.ini的檔案,內容為
[mysql]
# 設定mysql客戶端預設字符集
default-character-set=utf8mb4
[mysqld]
#設定3306埠
port = 3306 
# 設定mysql的安裝目錄
basedir=D:/mysql-8.0.12-winx64
# 設定mysql資料庫的資料的存放目錄
datadir=D:/mysql-8.0.12-winx64/data
# 允許最大連線數
max_connections=200
# 服務端使用的字符集預設為8位元編碼的latin1字符集
character-set-server=utf8
# 建立新表時將使用的預設儲存引擎
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password

執行命令

依次執行安裝命令 mysqld --initialize-insecuremysqld -install

D:\mysql-8.0.12-winx64\bin>mysqld --initialize-insecure

D:\mysql-8.0.12-winx64\bin>mysqld -install
Service successfully installed.

啟動服務 net start mysql

D:\mysql-8.0.12-winx64\bin>net start mysql
MySQL 服務正在啟動 ....
MySQL 服務已經啟動成功。

此時mysql沒有密碼,需要進行設定密碼,輸入:mysqladmin -u root password root

D:\mysql-8.0.12-winx64\bin>mysqladmin -u root password root
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

登陸

D:\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 9
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> use mysql;
Database changed

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.10 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)

由於8.0以上使用者密碼方式為caching_sha2_password,Navicat無法登陸,更改ROOT使用者的native_password密碼
mysql8.0以上密碼策略限制必須要大小寫加數字特殊符號

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '[email protected]';
Query OK, 0 rows affected (0.15 sec)

Navicat連線

image