您好,登錄后才能下訂單哦!
【前言】測試環境中經常需要多臺mysql數據庫來進行各種環境和場景的模擬,由于測試環境中的資源一般都是比較有限的,也就需要在一臺服務器上面搭建多個mysql數據庫來完成測試的需求。本文檔介紹在Centos6.4的環境中安裝多個mysql 5.7數據庫的操作方法。
【1】mysql數據庫軟件的安裝
mysql數據庫軟件官方提供了三種的安裝文件和方法,如下:
RPM方式安裝
二進制方式安裝
源碼編譯安裝
雖然源碼安裝的方式比較麻煩,但是個人還是習慣用源碼的方案安裝,mysql5.7的安裝跟早起5.5的安裝方式和步驟也幾乎一樣所以這里就不再說明了。
【2】創建多個數據庫
軟件的安裝完成其實都是一樣的,就是創建數據庫的時候有點不一樣。
2.1 進行數據文件目錄的規劃,本環境安裝了5個數據庫,在/data下面創建5個文件夾,并用端口號區分
點擊( 此處 )折疊或打開
[
root@db01 data
]
#
pwd
/data
[
root@db01 data
]
#
ll
drwxr
-
xr
-
x
.
6 mysql mysql 4096 7月 8 05
:
00 mysql3306
drwxr
-
xr
-
x
.
6 mysql mysql 4096 7月 20 21
:
46 mysql3307
drwxr
-
xr
-
x
.
7 mysql mysql 4096 7月 20 21
:
46 mysql3308
drwxr
-
xr
-
x
.
6 mysql mysql 4096 7月 20 21
:
46 mysql3309
drwxr - xr - x . 5 mysql mysql 4096 7月 20 21 : 46 mysql3310
2.2 進行參數文件的配置
點擊( 此處 )折疊或打開
|
2.3 創建數據庫,創建的過程中需要記錄數據庫的初始密碼
依次創建其他數據庫,記錄默認的隨機密碼
點擊( 此處 )折疊或打開
|
mysql3308的安裝
|
mysql3309的安裝
[
root@db01 mysql3307
]
#
/usr/
local
/
mysql/bin/mysqld
-
-
initialize
-
-
datadir
=
/
data/mysql3309
2017
-
07
-
20T14
:
33
:
32
.
801680Z 0
[
Warning
]
TIMESTAMP with implicit DEFAULT value is deprecated
.
Please use
-
-
explicit_defaults_for_timestamp server
option
(
see documentation
for
more details
)
.
2017
-
07
-
20T14
:
33
:
35
.
102950Z 0
[
Warning
]
InnoDB
:
New log files created
,
LSN
=
45790
2017
-
07
-
20T14
:
33
:
35
.
443411Z 0
[
Warning
]
InnoDB
:
Creating foreign key constraint system tables
.
2017
-
07
-
20T14
:
33
:
35
.
557451Z 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
:
69acd736
-
6d58
-
11e7
-
a436
-
000c29a755d3
.
2017
-
07
-
20T14
:
33
:
35
.
562713Z 0
[
Warning
]
Gtid table is
not
ready to be used
.
Table
'mysql.gtid_executed'
cannot be opened
.
2017
-
07
-
20T14
:
33
:
35
.
607109Z 1
[
Note
]
A temporary password is generated
for
root@localhost
:
sDXL5hh71I
>
R
數據庫mysql3310
點擊(
此處
)折疊或打開
[
root@db01 mysql3307
]
#
/usr/
local
/
mysql/bin/mysqld
-
-
initialize
-
-
datadir
=
/
data/mysql3310
2017
-
07
-
20T14
:
34
:
14
.
881243Z 0
[
Warning
]
TIMESTAMP with implicit DEFAULT value is deprecated
.
Please use
-
-
explicit_defaults_for_timestamp server
option
(
see documentation
for
more details
)
.
2017
-
07
-
20T14
:
34
:
17
.
227399Z 0
[
Warning
]
InnoDB
:
New log files created
,
LSN
=
45790
2017
-
07
-
20T14
:
34
:
17
.
744012Z 0
[
Warning
]
InnoDB
:
Creating foreign key constraint system tables
.
2017
-
07
-
20T14
:
34
:
17
.
904000Z 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
:
82ea694b
-
6d58
-
11e7
-
a566
-
000c29a755d3
.
2017
-
07
-
20T14
:
34
:
17
.
908498Z 0
[
Warning
]
Gtid table is
not
ready to be used
.
Table
'mysql.gtid_executed'
cannot be opened
.
2017
-
07
-
20T14
:
34
:
17
.
923365Z 1
[
Note
]
A temporary password is generated
for
root@localhost
:
Rq4
*
Teq#l
;
Ve
【3】 修改數據庫的初始密碼
先啟動數據庫
[
root@db01 mysql3307
]
#
/usr/
local
/
mysql/bin/mysqld_multi start
修改默認密碼
[
root@db01 mysql3307
]
#
mysqladmin
-
u root
-
p
-
P 3307
-
S /tmp/mysql
.
sock7 password
Enter
password
:
輸入默認密碼
New password
:
Confirm new password
:
Warning : Since password will be sent to server in plain text , use ssl connection to ensure password safety .
登錄數據庫
[root@db01 mysql3307]# mysql -P 3307 -S /tmp/mysql.sock7 -u root – p
用默認的密碼登錄會有以下的提示信息:
點擊( 此處 )折疊或打開
mysql
>
show databases
;
ERROR 1820 ( HY000 ) : You must reset your password using ALTER USER statement before executing this statement .
【4】設置mysqld_multi stop的關閉權限
默認的情況下,不能通過mysqld_multi關閉數據庫,需要進行額外的設置,步驟如下:
創建mysql關閉的用戶
[
root@db01 mysql3307
]
#
mysql
-
u root
-
p
-
P 3310
-
S /tmp/mysql
.
sock10
Enter
password
:
mysql
>
grant shutdown on
*
.
*
to
'mysql'
@
'localhost'
identified by
'mysql'
;
mysql
>
flush privileges
[
root@db01 mysql3307
]
#
cat /etc/my
.
cnf
[
mysqld_multi
]
mysqld
=
/usr/
local
/
mysql/bin/mysqld_safe
#basedir
=
/usr/
local
/
mysql
mysqladmin
=
/usr/
local
/
mysql/bin/mysqladmin
user
=
mysql
pass
=
mysql
點擊(
此處
)折疊或打開
設置參數文件的賬戶
點擊(
此處
)折疊或打開
通過以上的操作,便完成了在單臺服務器上面安裝多個mysql數據庫的操作;
附加:常用的操作語句
/usr/local/mysql/bin/mysqld_multi start #啟動所有的數據庫
/usr/local/mysql/bin/mysqld_multi start 7 #啟動單臺數據庫
/usr/local/mysql/bin/mysqld_multi stop #關閉所有的數據庫
/usr/local/mysql/bin/mysqld_multi stop 7 #關閉單臺數據庫
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。