1. 程式人生 > >MySQL在windows下相關的安裝和配置操作,多個MySQL的安裝詳細教程

MySQL在windows下相關的安裝和配置操作,多個MySQL的安裝詳細教程

我的部落格介紹了大部分安裝教程

https://blog.csdn.net/m0_37520980/article/details/80353315

當一臺計算機安裝多個MySQL的時候就需要一些下面的配置

mysqld --install [服務名] //這裡可以設定服務名

重新解釋一下安裝的操作各個含義 

D:\Program Files\mysql-8.0.11>cd bin     //切換到bin目錄下

D:\Program Files\mysql-8.0.11\bin>mysqld --remove //我以前安裝過mysql,先移除
Service successfully removed.

D:\Program Files\mysql-8.0.11\bin>mysqld --install    //安裝mysql,注意這裡都是兩個小橫線
Service successfully installed.
D:\Program Files\mysql-8.0.11\bin>mysqld --install mysql5.6//這裡可以設定服務名
設定服務名在一個機器安裝多個MySQL服務時可以用到,建議服務名全部用小寫,否則服務無法啟動


D:\Program Files\mysql-8.0.11\bin>mysqld --initialize --console    //注意這裡會生成一個密碼
//在mysql5.6版本時,此步驟不能要,否則服務無法啟動,
2018-05-17T07:59:00.988023Z 0 [System] [MY-013169] [Server] D:\Program Files\mysql-8.0.11\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 3556
2018-05-17T07:59:25.239288Z 5 [Note] [MY-010454] [Server] A temporary password is generated for 
[email protected]
host: 3<?*Yfr3>gdw //這裡3<?*Yfr3>gdw就是隨機生成的密碼 2018-05-17T07:59:45.170784Z 0 [System] [MY-013170] [Server] D:\Program Files\mysql-8.0.11\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed D:\Program Files\mysql-8.0.11\bin>net start mysql //啟動mysql服務 MySQL 服務正在啟動 .. MySQL 服務已經啟動成功。 D:\Program Files\mysql-8.0.11\bin>mysql -uroot -p //登入mysql Enter password: ************ //密碼就是上面的密碼 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.11 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.18 sec)//修改密碼成功 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.10 sec) mysql>

 

在安裝了mysql 8.0.11之後又安裝了mysql 5.6,現在我們再裝一個MySQL 5.7 

記錄一下過程

首先去官網下載 ----> 解壓  配置環境變數 ------> 然後新建data資料夾---->新建my.ini

注意修改一下埠 我的修改成如下的樣子

[mysql]
# 設定mysql客戶端預設字符集
default-character-set=utf8

[mysqld]
#設定3308埠,由於以前使用了3306和3307了,現在使用3308
port = 3308

# 設定mysql的安裝目錄,根據自己目錄修改
basedir=D:\Program Files\mysql-5.7.23

# 設定mysql資料庫的資料的存放目錄
datadir=D:\Program Files\mysql-5.7.23\data

# 允許最大連線數
max_connections=1000

# 服務端使用的字符集預設為8位元編碼的latin1字符集
character-set-server=utf8

# 建立新表時將使用的預設儲存引擎
default-storage-engine=INNODB
###下面的這些配置我沒用####
#忘記密碼時使用
#skip-grant-tables
#設定協議認證方式
#default_authentication_plugin=mysql_native_password

然後就是一通安裝服務   初始化資料庫

D:\Program Files\mysql-5.7.23\bin>net stop mysql5.6
mysql5.6 服務正在停止..
mysql5.6 服務已成功停止。

D:\Program Files\mysql-5.7.23\bin>mysqld --install mysql5.7
Service successfully installed.

D:\Program Files\mysql-5.7.23\bin>mysqld --initialize --console
2018-08-28T06:36:00.740573Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-28T06:36:01.095911Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-28T06:36:01.157061Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-28T06:36:01.240661Z 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: a141f86a-aa8c-11e8-8b4d-3c970ecc8cb1.
2018-08-28T06:36:01.245321Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-28T06:36:01.601113Z 1 [Note] A temporary password is generated for [email protected]: H?HaNyCfH0h4

D:\Program Files\mysql-5.7.23\bin>net start mysql5.7
mysql5.7 服務正在啟動 .
mysql5.7 服務已經啟動成功。


D:\Program Files\mysql-5.7.23\bin>mysql -h localhost -P3308 -uroot -p
Enter password: ************
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

發現無法連線!!!

找了一會原因,發現服務有問題

發現5.6和5.7的路徑竟然是一樣的,果斷刪除服務

D:\Program Files\mysql-5.7.23\bin>net stop mysql5.7
mysql5.7 服務正在停止.
mysql5.7 服務已成功停止。


D:\Program Files\mysql-5.7.23\bin>mysqld --remove mysql5.7
Service successfully removed.

修改環境變數

 

path中將5.7的環境變數移到前面,

然後以管理身份重新開啟一個命令視窗!!!

安裝服務

C:\windows\system32>D:

D:\>cd D:\Program Files\mysql-5.7.23\bin

D:\Program Files\mysql-5.7.23\bin>mysqld --install mysql5.7
Service successfully installed.

檢視服務正常

刪除5.7路徑下data目錄中的所有內容(不刪除直接啟動服務也是可以的)

C:\windows\system32>D:

D:\>cd D:\Program Files\mysql-5.7.23\bin

D:\Program Files\mysql-5.7.23\bin>mysqld --install mysql5.7
Service successfully installed.

//初始化資料庫,如果沒有刪除data資料夾可以不用初始化,直接啟動服務即可
D:\Program Files\mysql-5.7.23\bin>mysqld --initialize --console
2018-08-28T07:21:38.729028Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-28T07:21:39.039243Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-28T07:21:39.098293Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-28T07:21:39.171396Z 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: 013123c2-aa93-11e8-9acb-3c970ecc8cb1.
2018-08-28T07:21:39.174562Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-28T07:21:39.193724Z 1 [Note] A temporary password is generated for [email protected]: )bMStHuCw2QE

//啟動服務
D:\Program Files\mysql-5.7.23\bin>net start mysql5.7
mysql5.7 服務正在啟動 .
mysql5.7 服務已經啟動成功。

//指定埠連結資料庫
D:\Program Files\mysql-5.7.23\bin>mysql -h localhost -P3308 -uroot -p
Enter password: ************   //這裡是密碼,部落格中解釋過了,如果沒有重新初始化就是上一個密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23

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.00 sec)

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

至此,資料庫安裝完成。

效果,三個版本的資料庫都啟動成功,各自佔用不同的埠