dbdeployer 快速安裝MySQL8.0各測試環境

zping發表於2018-05-28
  Linux系統必須安裝有Go語言:
下載最新的包:https://github.com/datacharmer/dbdeployer/releases  
   解壓:  tar -xzf dbdeployer-1.5.0.linux.tar.gz
   賦予執行許可權: chmod +x dbdeployer-1.5.0.linux
   拷貝到bin目錄: sudo mv dbdeployer-1.5.0.linux /usr/local/bin/dbdeployer

dbdeployer可以快速搭建多個MySQL測試環境(主從複製,主主複製,GTID複製,組複製(單主或多主),多源複製等)

部署MySQL環境都是秒級別(10-30秒,根據例項多少有關),使用起來很方便,還有各種管理命令。

dbdeployer unpack mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz --sandbox-binary=/usr/local dbdeployer deploy single 8.0.11 --bind-address=0.0.0.0 --port=3308 --sandbox-home=/home/data --sandbox-binary=/usr/local --sandbox-home 資料檔案的安裝目錄 --sandbox-binary 是安裝MySQL的二進位制檔案程式目錄 --bind-address 4個0代表全部 --port 代表MySQL的埠 -- cd 到/home/data下 --mysql 8.0.11 建立使用者  ./use 進去 修改密碼和許可權,否則不能修改Authentication plugin 'caching_sha2_password' cannot be loaded: ALTER user'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'cc.123'; create USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'cc.123'; FLUSH PRIVILEGES; --再授權 mysql -u root -p -S /tmp/mysql_sandbox3308.sock -- 進入 grant all on *.* to 'root'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;
如果想在安裝的時候就賦予許可權,直接使用引數:
--post-grants-sql="grant all on *.* to 'root'@'%' WITH GRANT OPTION "

--刪除已經部署的mysql

  dbdeployer delete rsandbox_8_0_11 --sandbox-home=/home/data -- sandbox-binary=/usr/local;

   --這裡的:rsandbox_8_0_11  是資料夾名稱

   --部署1主多從(1拖4) (using ports 18601, 18602, 18603,18604)
   dbdeployer deploy replication 8.0.11 --bind-address=0.0.0.0 --base-port=18600 --sandbox-home=/home/data --sandbox-binary=/usr/local --nodes=4;

  

   --部署4個mysql,(using ports 18601, 18602, 18603,18604)
   dbdeployer deploy multiple 8.0.11 --bind-address=0.0.0.0 --base-port=18600 --sandbox-home=/home/data --sandbox-binary=/usr/local --nodes=4;

   安裝3主2從(多主多從):

     dbdeployer deploy replication --topology=fan-in   --nodes=5 --master-list="1,2,3"  --bind-address=0.0.0.0  --native-auth-plugin  --slave-list="4,5"  8.0.11 --sandbox-home=/home/data  --remote-access="%" --sandbox-binary=/usr/local  --db-password="cc.123" --db-user="sa"  --post-grants-sql="grant all on *.* to 'sa'@'%' WITH GRANT OPTION "

      --remote-access="%"  賬戶遠端訪問的IP,% 為全部

      --db-user 新資料庫賬戶 

      --db-password 資料庫密碼

      --post-grants-sql  後面執行的資料庫授權Sql

      --native-auth-plugin  客戶端如SQLLog可以訪問MySQL,是在MySQL 8.0.4+ 有效

   安裝組複製:

    dbdeployer deploy replication --topology=group     --bind-address=0.0.0.0      8.0.11 --sandbox-home=/home/data --remote-access="%" --sandbox-binary=/usr/local --native-auth-plugin  --db-password="cc.123" --db-user="sa"  --post-grants-sql="grant all on *.* to 'sa'@'%' WITH GRANT OPTION ";

   加上:--single-primary  明確是單主   

    dbdeployer deploy --topology=all-masters replication  --bind-address=0.0.0.0   8.0.11 --sandbox-home=/home/td  --remote-access="%" --sandbox-binary=/usr/local --native-auth-plugin --db-password="cc.123" --db-user="sa"  --post-grants-sql="grant all on *.* to 'sa'@'%' WITH GRANT OPTION " --concurrent;


詳細說明:
      --base-port int                 Overrides default base-port (for multiple sandboxes)
      --binary-version string         Specifies the version when the basedir directory name does not contain it (i.e. it is not x.x.xx)
      --bind-address string           defines the database bind-address  (default "127.0.0.1")
      --concurrent                    Runs multiple sandbox deployments concurrently
      --custom-mysqld string          Uses an alternative mysqld (must be in the same directory as regular mysqld)
  -p, --db-password string            database password (default "msandbox")
  -u, --db-user string                database user (default "msandbox")
      --defaults strings              Change defaults on-the-fly (--defaults=label:value)
      --disable-mysqlx                Disable MySQLX plugin (8.0.11+)
      --enable-general-log            Enables general log for the sandbox (MySQL 5.1+)
      --enable-mysqlx                 Enables MySQLX plugin (5.7.12+)
      --expose-dd-tables              In MySQL 8.0+ shows data dictionary tables
      --force                         If a destination sandbox already exists, it will be overwritten
      --gtid                          enables GTID
  -h, --help                          help for deploy
      --init-general-log              uses general log during initialization (MySQL 5.1+)
  -i, --init-options strings          mysqld options to run during initialization
      --keep-server-uuid              Does not change the server UUID
      --my-cnf-file string            Alternative source file for my.sandbox.cnf
  -c, --my-cnf-options strings        mysqld options to add to my.sandbox.cnf
      --native-auth-plugin            in 8.0.4+, uses the native password auth plugin
      --port int                      Overrides default port
      --post-grants-sql strings       SQL queries to run after loading grants
      --post-grants-sql-file string   SQL file to run after loading grants
      --pre-grants-sql strings        SQL queries to run before loading grants
      --pre-grants-sql-file string    SQL file to run before loading grants
      --remote-access string          defines the database access  (default "127.%")
      --rpl-password string           replication password (default "rsandbox")
      --rpl-user string               replication user (default "rsandbox")
      --sandbox-directory string      Changes the default sandbox directory
      --skip-load-grants              Does not load the grants
      --skip-report-host              Does not include report host in my.sandbox.cnf
      --skip-report-port              Does not include report port in my.sandbox.cnf
      --skip-start                    Does not start the database server
      --use-template strings          [template_name:file_name] Replace existing template with one from file 

說明:

        $ dbdeployer deploy replication 5.7.21
        # (implies topology = master-slave) 預設主從

        $ dbdeployer deploy --topology=master-slave replication 5.7.21
        # (explicitly setting topology) 明確主從

        $ dbdeployer deploy --topology=group replication 5.7.21  組複製多主
        $ dbdeployer deploy --topology=group replication 8.0.4 --single-primary 組複製單主
        $ dbdeployer deploy --topology=all-masters replication 5.7.21   多主複製
        $ dbdeployer deploy --topology=fan-in replication 5.7.21  多主單(多)從複製 

 

   注意: 安裝的過程中當前目錄一定有,不然報錯。比如在刪除的rsandbox_8_0_11資料夾下執行dbdeployer命令

   配置後的備份:cd到MySQL的bin下執行   

./mysqldump -h 192.168.60.167  -u sa -p -P8011 --socket=/tmp/mysql_sandbox8011.sock  test > test_db.sql;

  

 

相關文章