1. 程式人生 > >MySQL 解壓版在Windows下的安裝與配置

MySQL 解壓版在Windows下的安裝與配置

從 MySQL 官網下載解壓版本的安裝包

下載完成後解壓到安裝位置,我的安裝位置為

D:\database\mysql-5.7.24

D:\database\mysql-5.7.24 目錄下新建配置檔案 my.ini

[mysql]
default-character-set=utf8
[mysqld]
port = 3306
basedir=D:\database\mysql-5.7.24
datadir=D:\database\mysql-5.7.24\data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB

5.7.24 版本安裝包已不包含 my.default.ini 配置檔案和 data 目錄。

data 目錄不要新建,my.ini 配置檔案可以新建,data 目錄通過初始化命令來建立。

以管理員的方式開啟 cmd 命令視窗,進入 D:\database\mysql-5.7.24\bin 目錄下執行以下命令,初始化資料庫。

D:\database\mysql-5.7.24\bin>mysqld --initialize --console
2018-11-05T09:09:27.549968Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-05T09:09:29.253650Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-05T09:09:29.850310Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-05T09:09:30.180265Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 80b77eb4-e0da-11e8-ac91-5215d904abe2.
2018-11-05T09:09:30.225972Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-05T09:09:30.244958Z 1 [Note] A temporary password is generated for 
[email protected]
: T%loP7wOUdOz

mysqld --initialize 會隨機生成臨時密碼 T%loP7wOUdOz

配置 MySQL 為Windows 服務

mysqld install 

管理員的身份執行 CMD,啟動 MySQL

net start|stop mysql
[[email protected] mysql]# mysql -u root -pT%loP7wOUdOz
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 3
Server version: 5.7.24

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> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
## 首次登陸需要修改root使用者密碼
mysql> alter user 'root'@'localhost' identified by 'root';或者alter user user() identified by 'root';
Query OK, 0 rows affected (0.00 sec)

## 配置root用遠端登陸且具有所有庫的許可權
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)