歡迎關注本人公衆號
mysql8 的安裝先比較之前的版本複雜了一些,下面就一步一步安裝。
下載
到 mysql官網 下載最新版本的mysql
下載完成後解壓,並新建my.ini
文件
my.ini 文件配置
my.ini
文件內容:
[mysqld]
# 設置3306端口
port=3306
# 設置mysql的安裝目錄
basedir=C:\Program Files\mysql-8.0.20-winx64
# 設置mysql數據庫的數據的存放目錄
datadir=C:\Program Files\mysql-8.0.20-winx64\Data
# 允許最大連接數
max_connections=200
# 允許連接失敗的次數。
max_connect_errors=10
# 服務端使用的字符集默認爲utf8mb4
character-set-server=utf8mb4
# 創建新表時將使用的默認存儲引擎
default-storage-engine=INNODB
# 默認使用“mysql_native_password”插件認證
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
# 設置mysql客戶端默認字符集
default-character-set=utf8mb4
[client]
# 設置mysql客戶端連接服務端時默認使用的端口
port=3306
default-character-set=utf8mb4
環境變量配置
環境變量中配置MySQL的bin的地址:
初始化MySQL
以管理員權限運行CMD:
輸入mysqld --initialize --console
注意,這裏的root@localhost: wD3l-a.r=2yP
時用戶名和密碼,先記錄下來。
安裝並啓動MySQL服務
C:\Program Files\mysql-8.0.20-winx64\bin>mysqld --initialize --console
2020-07-03T07:59:08.324357Z 0 [System] [MY-013169] [Server] C:\Program Files\mysql-8.0.20-winx64\bin\mysqld.exe (mysqld 8.0.20) initializing of server in progress as process 17184
2020-07-03T07:59:08.352557Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-03T07:59:09.538150Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-03T07:59:10.701709Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wD3l-a.r=2yP
C:\Program Files\mysql-8.0.20-winx64\bin>mysqld --install
Service successfully installed.
C:\Program Files\mysql-8.0.20-winx64\bin>net start mysql
MySQL 服務正在啓動 ..
MySQL 服務已經啓動成功。
修改密碼
先用剛從的初始密碼登陸,然後用alter user 'root'@'localhost' identified by '123456';
命令修改密碼。
C:\Program Files\mysql-8.0.20-winx64\bin>mysql -uroot -pwD3l-a.r=2yP
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.20
Copyright (c) 2000, 2020, 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 '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
注意:
- 我們安裝的時mysql8 版本,
update mysql.user set password='newpassword' where user='root';
和update mysql.user set password=PASSWORD('newpassword') where User='root';
這兩條命令已經失效。 flush privileges;
刷新命令不可以省略哦
使用新密碼登陸
C:\Program Files\mysql-8.0.20-winx64\bin>mysql -uroot -p123456
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 12
Server version: 8.0.20 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)