溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

轉(zhuǎn)載連接 http://blog.itpub.net/12679300/viewspace-2144619/

發(fā)布時(shí)間:2020-08-10 11:08:02 來源:ITPUB博客 閱讀:173 作者:18141908802 欄目:MySQL數(shù)據(jù)庫(kù)

【前言】測(cè)試環(huán)境中經(jīng)常需要多臺(tái)mysql數(shù)據(jù)庫(kù)來進(jìn)行各種環(huán)境和場(chǎng)景的模擬,由于測(cè)試環(huán)境中的資源一般都是比較有限的,也就需要在一臺(tái)服務(wù)器上面搭建多個(gè)mysql數(shù)據(jù)庫(kù)來完成測(cè)試的需求。本文檔介紹在Centos6.4的環(huán)境中安裝多個(gè)mysql 5.7數(shù)據(jù)庫(kù)的操作方法。

【1】mysql數(shù)據(jù)庫(kù)軟件的安裝

mysql數(shù)據(jù)庫(kù)軟件官方提供了三種的安裝文件和方法,如下:

  • RPM方式安裝

  • 二進(jìn)制方式安裝

  • 源碼編譯安裝

雖然源碼安裝的方式比較麻煩,但是個(gè)人還是習(xí)慣用源碼的方案安裝,mysql5.7的安裝跟早起5.5的安裝方式和步驟也幾乎一樣所以這里就不再說明了。


【2】創(chuàng)建多個(gè)數(shù)據(jù)庫(kù)

軟件的安裝完成其實(shí)都是一樣的,就是創(chuàng)建數(shù)據(jù)庫(kù)的時(shí)候有點(diǎn)不一樣。

2.1 進(jìn)行數(shù)據(jù)文件目錄的規(guī)劃,本環(huán)境安裝了5個(gè)數(shù)據(jù)庫(kù),在/data下面創(chuàng)建5個(gè)文件夾,并用端口號(hào)區(qū)分


點(diǎn)擊( 此處 )折疊或打開

  1. [ root@db01 data ] #  pwd

  2. /data

  3. [ root@db01 data ] #  ll

  4. drwxr - xr - x .  6 mysql mysql 4096 7月 8 05 : 00 mysql3306

  5. drwxr - xr - x .  6 mysql mysql 4096 7月 20 21 : 46 mysql3307

  6. drwxr - xr - x .  7 mysql mysql 4096 7月 20 21 : 46 mysql3308

  7. drwxr - xr - x .  6 mysql mysql 4096 7月 20 21 : 46 mysql3309

  8. drwxr - xr - x .  5 mysql mysql 4096 7月 20 21 : 46 mysql3310

2.2 進(jìn)行參數(shù)文件的配置


點(diǎn)擊( 此處 )折疊或打開

  1. [ root@db01 data ] #  vi /etc/my . cnf


  2. [ mysqld_multi ]

  3. mysqld  =  /usr/ local / mysql/bin/mysqld_safe

  4. #basedir  =  /usr/ local / mysql

  5. mysqladmin  =  /usr/ local / mysql/bin/mysqladmin

  6. user  =  mysql

  7. pass  =  mysql

  8. #password  =  mysql

  9. #bindir  =  /usr/ local / mysql/bin


  10. [ mysqld7 ]

  11. port  =  3307

  12. socket  =  /tmp/mysql . sock7

  13. pid - file  =  /data/mysql3307/hostname . pid7

  14. datadir  =  /data/mysql3307

  15. user  =  mysql

  16. basedir  =  /usr/ local / mysql

  17. log - bin  =  /data/mysql3307/bin - log

  18. server_id  =  7

  19. gtid_mode  =  ON

  20. enforce - gtid - consistency = TRUE

  21. log_slave_updates =  ON

  22. #skip - grant - tables


  23. [ mysqld8 ]

  24. socket  =  /tmp/mysql . sock8

  25. port  =  3308

  26. pid - file  =  /data/mysql3308/hostname . pid8

  27. datadir  =  /data/mysql3308

  28. user  =  mysql

  29. basedir  =  /usr/ local / mysql

  30. #skip - grant - tables

  31. log - bin  =  /data/mysql3308/bin - log

  32. server_id = 8

  33. gtid_mode = ON

  34. enforce - gtid - consistency = TRUE

  35. log_slave_updates =  ON


  36. [ mysqld9 ]

  37. socket  =  /tmp/mysql . sock9

  38. port  =  3309

  39. pid - file  =  /data/mysql3309/hostname . pid9

  40. datadir  =  /data/mysql3309

  41. user  =  mysql

  42. basedir  =  /usr/ local / mysql

  43. #skip - grant - tables

  44. log - bin  =  /data/mysql3309/bin - log

  45. server_id =  9

  46. gtid_mode = ON

  47. enforce - gtid - consistency = TRUE

  48. log_slave_updates =  ON


  49. [ mysqld10 ]

  50. socket  =  /tmp/mysql . sock10

  51. port  =  3310

  52. pid - file  =  /data/mysql3310/hostname . pid10

  53. datadir  =  /data/mysql3310

  54. user  =  mysql

  55. basedir  =  /usr/ local / mysql

  56. #skip - grant - tables

  57. log - bin  =  /data/mysql3310/bin - log

  58. server_id =  10

  59. gtid_mode = ON

  60. enforce - gtid - consistency = TRUE

  61. log_slave_updates =  ON


2.3 創(chuàng)建數(shù)據(jù)庫(kù),創(chuàng)建的過程中需要記錄數(shù)據(jù)庫(kù)的初始密碼

依次創(chuàng)建其他數(shù)據(jù)庫(kù),記錄默認(rèn)的隨機(jī)密碼

  • mysql3307的安裝

點(diǎn)擊( 此處 )折疊或打開

  1. [ root@db01 data ] #  /usr/ local / mysql/bin/mysqld  - - initialize  - - datadir = / data/mysql3307

  2. 2017 - 07 - 20T14 : 31 : 01 . 890314Z 0  [ Warning ]  TIMESTAMP with implicit DEFAULT value is deprecated .  Please use  - - explicit_defaults_for_timestamp server  option   ( see documentation  for  more details ) .

  3. 2017 - 07 - 20T14 : 31 : 09 . 081679Z 0  [ Warning ]  InnoDB :  New log files created ,  LSN = 45790

  4. 2017 - 07 - 20T14 : 31 : 09 . 626403Z 0  [ Warning ]  InnoDB :  Creating foreign key constraint system tables .

  5. 2017 - 07 - 20T14 : 31 : 09 . 867983Z 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 :  12d65efe - 6d58 - 11e7 - 9d39 - 000c29a755d3 .

  6. 2017 - 07 - 20T14 : 31 : 09 . 873982Z 0  [ Warning ]  Gtid table is  not  ready to be used .  Table  'mysql.gtid_executed'  cannot be opened .

  7. 2017 - 07 - 20T14 : 31 : 09 . 923044Z 1  [ Note ]  A temporary password is generated  for  root@localhost :  wAQ * p > . O : 4 , p

  • mysql3308的安裝

  1. [ root@db01 mysql3307 ] #  cat auto . cnf

  2. [ auto ]

  3. server - uuid = 12d65efe - 6d58 - 11e7 - 9d39 - 000c29a755d3

  4. [ root@db01 mysql3307 ] #  /usr/ local / mysql/bin/mysqld  - - initialize  - - datadir = / data/mysql3308

  5. 2017 - 07 - 20T14 : 32 : 36 . 027225Z 0  [ Warning ]  TIMESTAMP with implicit DEFAULT value is deprecated .  Please use  - - explicit_defaults_for_timestamp server  option   ( see documentation  for  more details ) .

  6. 2017 - 07 - 20T14 : 32 : 38 . 601806Z 0  [ Warning ]  InnoDB :  New log files created ,  LSN = 45790

  7. 2017 - 07 - 20T14 : 32 : 39 . 071963Z 0  [ Warning ]  InnoDB :  Creating foreign key constraint system tables .

  8. 2017 - 07 - 20T14 : 32 : 39 . 167438Z 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 :  48106897 - 6d58 - 11e7 - a1b9 - 000c29a755d3 .

  9. 2017 - 07 - 20T14 : 32 : 39 . 172770Z 0  [ Warning ]  Gtid table is  not  ready to be used .  Table  'mysql.gtid_executed'  cannot be opened .

  10. 2017 - 07 - 20T14 : 32 : 39 . 212540Z 1  [ Note ]  A temporary password is generated  for  root@localhost :  Ak3XwQpb = ta0

  • mysql3309的安裝

  1. [ root@db01 mysql3307 ] #  /usr/ local / mysql/bin/mysqld  - - initialize  - - datadir = / data/mysql3309

  2. 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 ) .

  3. 2017 - 07 - 20T14 : 33 : 35 . 102950Z 0  [ Warning ]  InnoDB :  New log files created ,  LSN = 45790

  4. 2017 - 07 - 20T14 : 33 : 35 . 443411Z 0  [ Warning ]  InnoDB :  Creating foreign key constraint system tables .

  5. 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 .

  6. 2017 - 07 - 20T14 : 33 : 35 . 562713Z 0  [ Warning ]  Gtid table is  not  ready to be used .  Table  'mysql.gtid_executed'  cannot be opened .

  7. 2017 - 07 - 20T14 : 33 : 35 . 607109Z 1  [ Note ]  A temporary password is generated  for  root@localhost :  sDXL5hh71I > R

  • 數(shù)據(jù)庫(kù)mysql3310

點(diǎn)擊( 此處 )折疊或打開

  1. [ root@db01 mysql3307 ] #  /usr/ local / mysql/bin/mysqld  - - initialize  - - datadir = / data/mysql3310

  2. 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 ) .

  3. 2017 - 07 - 20T14 : 34 : 17 . 227399Z 0  [ Warning ]  InnoDB :  New log files created ,  LSN = 45790

  4. 2017 - 07 - 20T14 : 34 : 17 . 744012Z 0  [ Warning ]  InnoDB :  Creating foreign key constraint system tables .

  5. 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 .

  6. 2017 - 07 - 20T14 : 34 : 17 . 908498Z 0  [ Warning ]  Gtid table is  not  ready to be used .  Table  'mysql.gtid_executed'  cannot be opened .

  7. 2017 - 07 - 20T14 : 34 : 17 . 923365Z 1  [ Note ]  A temporary password is generated  for  root@localhost :  Rq4 * Teq#l ; Ve

【3】 修改數(shù)據(jù)庫(kù)的初始密碼

先啟動(dòng)數(shù)據(jù)庫(kù)


  1. [ root@db01 mysql3307 ] #  /usr/ local / mysql/bin/mysqld_multi start

  2. 修改默認(rèn)密碼

  3. [ root@db01 mysql3307 ] #  mysqladmin  - u root  - - P 3307  - S /tmp/mysql . sock7 password

  4. Enter  password :  輸入默認(rèn)密碼

  5. New password :

  6. Confirm new password :

  7. Warning :  Since password will be sent to server  in  plain text ,  use ssl connection to ensure password safety .


登錄數(shù)據(jù)庫(kù)

[root@db01 mysql3307]# mysql -P 3307 -S /tmp/mysql.sock7 -u root  p


用默認(rèn)的密碼登錄會(huì)有以下的提示信息:

點(diǎn)擊( 此處 )折疊或打開

  1. mysql >  show databases ;

  2. ERROR 1820  ( HY000 ) :  You must reset your password using ALTER USER statement before executing  this  statement .


【4】設(shè)置mysqld_multi stop的關(guān)閉權(quán)限

默認(rèn)的情況下,不能通過mysqld_multi關(guān)閉數(shù)據(jù)庫(kù),需要進(jìn)行額外的設(shè)置,步驟如下:

創(chuàng)建mysql關(guān)閉的用戶
點(diǎn)擊( 此處 )折疊或打開

  1. [ root@db01 mysql3307 ] #  mysql  - u root  - - P 3310  - S /tmp/mysql . sock10

  2. Enter  password :

  3. mysql >  grant shutdown on  * . *  to  'mysql' @ 'localhost'  identified by  'mysql' ;

  4. mysql >  flush privileges

設(shè)置參數(shù)文件的賬戶
點(diǎn)擊( 此處 )折疊或打開
  1. [ root@db01 mysql3307 ] #  cat /etc/my . cnf

  2. [ mysqld_multi ]

  3. mysqld  =  /usr/ local / mysql/bin/mysqld_safe

  4. #basedir  =  /usr/ local / mysql

  5. mysqladmin  =  /usr/ local / mysql/bin/mysqladmin

  6. user  =  mysql

  7. pass  =  mysql

通過以上的操作,便完成了在單臺(tái)服務(wù)器上面安裝多個(gè)mysql數(shù)據(jù)庫(kù)的操作;

附加:常用的操作語(yǔ)句

/usr/local/mysql/bin/mysqld_multi start #啟動(dòng)所有的數(shù)據(jù)庫(kù)

/usr/local/mysql/bin/mysqld_multi start 7 #啟動(dòng)單臺(tái)數(shù)據(jù)庫(kù)

/usr/local/mysql/bin/mysqld_multi stop #關(guān)閉所有的數(shù)據(jù)庫(kù)

/usr/local/mysql/bin/mysqld_multi stop 7 #關(guān)閉單臺(tái)數(shù)據(jù)庫(kù)


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI