MySQL環境搭建利器---Sandbox
MySQL環境搭建利器---Sandbox
https://metacpan.org/pod/MySQL::Sandbox
https://www.cnblogs.com/gomysql/p/3767445.html
https://www.howtoing.com/quick-db-setups-with-mysql-sandbox
http://blog.itpub.net/22664653/viewspace-2134256/
經常看見新同學對於安裝MySQL十分懼怕,這是因為不熟悉的緣故,確實原始碼編譯比較麻煩,缺少各種依賴包也夠折騰的。當然還有預編譯包,但是對於新同學來說好像都挺麻煩的。當然有yum安裝,但是我們需要多例項,測試多個版本就不方便了。那麼我來說說比較簡單的方法。使用沙箱環境。MySQL Sandbox是什麼呢?簡單來說就是一個沙盒,可以用於快速搭建mysql的環境,讓我們可以不用費勁的去安裝,或者編譯。通常對於學習來說是不錯的選擇。畢竟我們是自己學習,而不是線上環境。專案主頁: http://mysqlsandbox.net/。對於安裝也是非常簡單的。我這裡就採用 cpan來安裝,當然各位童鞋也可以採用原始碼安裝。看你口味了。我反正喜歡簡單,能滿足需求就行,或許這也是我的性格哈。:)
1.安裝cpan
yum install cpan -y
2.安裝軟體依賴的包
yum install perl-Test-Simple -y
3.安裝MySQL Sandbox
cpan MySQL::Sandbox
4.設定環境變數(否則會拋錯)
[root@localhost ~]# echo 'export SANDBOX_AS_ROOT=1' >> /root/.bash_profile [root@localhost ~]# source /root/.bash_profile
5.下載mysql二進位制軟體包(我這裡下載mysql5.6和mariadb-10,軟體各位童鞋自己搜尋,我這裡已經下載,如下)
[root@localhost mysql]# pwd /opt/mysql [root@localhost mysql]# ll total 588236 -rw-r--r--. 1 root root 295874759 Jun 4 04:56 mariadb-10.0.12-linux-x86_64.tar.gz -rw-r--r--. 1 root root 306470256 Jun 4 04:56 mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz [root@localhost mysql]#
6.在沙箱環境中執行我們mysql兩個例項
(1)首先建立mysql5.6的例項
[root@localhost mysql]# cd /opt/mysql/ [root@localhost mysql]# make_sandbox mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz unpacking /opt/mysql/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz Executing low_level_make_sandbox --basedir=/opt/mysql/5.6.12 \ --sandbox_directory=msb_5_6_12 \ --install_version=5.6 \ --sandbox_port=5612 \ --no_ver_after_name \ --my_clause=log-error=msandbox.err The MySQL Sandbox, version 3.0.44 (C) 2006-2013 Giuseppe Maxia installing with the following parameters: upper_directory = /root/sandboxes sandbox_directory = msb_5_6_12 sandbox_port = 5612 check_port = no_check_port = datadir_from = script install_version = 5.6 basedir = /opt/mysql/5.6.12 tmpdir = my_file = operating_system_user = root db_user = msandbox remote_access = 127.% bind_address = 127.0.0.1 ro_user = msandbox_ro rw_user = msandbox_rw repl_user = rsandbox db_password = msandbox repl_password = rsandbox my_clause = log-error=msandbox.err master = slaveof = high_performance = prompt_prefix = mysql prompt_body = [\h] {\u} (\d) > force = no_ver_after_name = 1 verbose = load_grants = 1 no_load_grants = no_run = no_show = do you agree? ([Y],n)
看見各種提示都給出了,相信童鞋們都看的懂,選擇Y同意。
do you agree? ([Y],n) y loading grants .... sandbox server started Your sandbox server was installed in $HOME/sandboxes/msb_5_6_12 [root@localhost mysql]#
最後會有安裝路徑的提示,預設在家目錄下的sandboxes下。我們可以看看
[root@localhost sandboxes]# pwd /root/sandboxes [root@localhost sandboxes]# ll total 40 -rwxr-xr-x. 1 root root 54 Jun 4 05:25 clear_all drwxr-xr-x. 4 root root 4096 Jun 4 05:25 msb_5_6_12 -rw-r--r--. 1 root root 3621 Jun 4 05:25 plugin.conf -rwxr-xr-x. 1 root root 56 Jun 4 05:25 restart_all -rwxr-xr-x. 1 root root 2139 Jun 4 05:25 sandbox_action -rwxr-xr-x. 1 root root 58 Jun 4 05:25 send_kill_all -rwxr-xr-x. 1 root root 54 Jun 4 05:25 start_all -rwxr-xr-x. 1 root root 55 Jun 4 05:25 status_all -rwxr-xr-x. 1 root root 53 Jun 4 05:25 stop_all -rwxr-xr-x. 1 root root 52 Jun 4 05:25 use_all [root@localhost sandboxes]#
那麼如何啟動mysql呢,預設安裝以後就啟動了。
[root@localhost ~]# pgrep -fl mysql2151 /bin/sh /opt/mysql/5.6.12/bin/mysqld_safe --defaults-file=/root/sandboxes/msb_5_6_12/my.sandbox.cnf2331 /opt/mysql/5.6.12/bin/mysqld --defaults-file=/root/sandboxes/msb_5_6_12/my.sandbox.cnf --basedir=/opt/mysql/5.6.12 --datadir=/root/sandboxes/msb_5_6_12/data --plugin-dir=/opt/mysql/5.6.12/lib/plugin --user=root --log-error=/root/sandboxes/msb_5_6_12/data/msandbox.err --pid-file=/root/sandboxes/msb_5_6_12/data/mysql_sandbox5612.pid --socket=/tmp/mysql_sandbox5612.sock --port=5612[root@localhost ~]#
可以殺掉程式,自己啟動看看,啟動停止指令碼在/root/sandboxes/msb_5_6_12
[root@localhost msb_5_6_12]# pkill -9 mysqld [root@localhost msb_5_6_12]# ./start sandbox server already started (found pid file /root/sandboxes/msb_5_6_12/data/mysql_sandbox5612.pid) sandbox server started [root@localhost msb_5_6_12]# rm -f /root/sandboxes/msb_5_6_12/data/mysql_sandbox5612.pid [root@localhost msb_5_6_12]# ./start . sandbox server started [root@localhost msb_5_6_12]#
登陸mysql瞧瞧
[root@localhost msb_5_6_12]# pwd /root/sandboxes/msb_5_6_12 [root@localhost msb_5_6_12]# ./use Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.12 MySQL Community Server (GPL) Copyright (c) 2000, 2013, 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 [localhost] {msandbox} ((none)) >
就這麼簡單哈,當然有複雜的用法,大家可以試試,通常這樣能快速部署一個mysql用於測試已經足夠了。(下面的是mariadb例項,安裝例項都是一樣的)
[root@localhost msb_10_0_10]# pwd/root/sandboxes/msb_10_0_10 [root@localhost msb_10_0_10]# ./use Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5Server version: 10.0.10-MariaDB MariaDB Server Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql [localhost] {msandbox} ((none)) >
各個mysql例項的埠號就是mysql的版本號哦:)
[root@localhost msb_10_0_10]# netstat -nltp | grep mysqld tcp 0 0 127.0.0.1:5612 0.0.0.0:* LISTEN 2547/mysqld tcp 0 0 127.0.0.1:10010 0.0.0.0:* LISTEN 3015/mysqld [root@localhost msb_10_0_10]#
對於需要部署多個例項呢?同一個版本部署多例項,其實也非常的簡單,提供了make_multiple_sandbox這個命令,具體的引數自行help。或者查閱官方文件。
對於部署多個例項,我們還可以新增一個環境變數,就是將例項安裝在指定的位置,
[root@mysql-server-01 mysql]# echo "export SANDBOX_HOME=/data/" >> /root/.bash_profile [root@mysql-server-01 mysql]# source /root/.bash_profile
下面預設部署3個例項(相同的版本)
[root@mysql-server-01 mysql]# make_multiple_sandbox mariadb-10.0.12-linux-x86_64.tar.gz
installing node 1
installing node 2
installing node 3
group directory installed in $SANDBOX_HOME/multi_msb_mariadb-10_0_12
[root@mysql-server-01 mysql]#
預設部署3個例項,想要部署更多例項可以加引數--how_many_nodes = number,上面部署完成以後我們看看。
[root@mysql-server-01 multi_msb_mariadb-10_0_12]# pwd /data/multi_msb_mariadb-10_0_12 [root@mysql-server-01 multi_msb_mariadb-10_0_12]# ll total 72 -rwxr-xr-x 1 root root 365 Jul 13 16:18 check_slaves -rwxr-xr-x 1 root root 432 Jul 13 16:18 clear_all -rw-r--r-- 1 root root 7811 Jul 13 16:18 connection.json -rw-r--r-- 1 root root 626 Jul 13 16:18 default_connection.json -rwxr-xr-x 1 root root 48 Jul 13 16:18 n1 -rwxr-xr-x 1 root root 48 Jul 13 16:18 n2 -rwxr-xr-x 1 root root 48 Jul 13 16:18 n3 drwxr-xr-x 4 root root 4096 Jul 13 16:17 node1 drwxr-xr-x 4 root root 4096 Jul 13 16:17 node2 drwxr-xr-x 4 root root 4096 Jul 13 16:18 node3 -rw-r--r-- 1 root root 1088 Jul 13 16:18 README -rwxr-xr-x 1 root root 204 Jul 13 16:18 restart_all -rwxr-xr-x 1 root root 460 Jul 13 16:18 send_kill_all -rwxr-xr-x 1 root root 432 Jul 13 16:18 start_all -rwxr-xr-x 1 root root 232 Jul 13 16:18 status_all -rwxr-xr-x 1 root root 425 Jul 13 16:18 stop_all -rwxr-xr-x 1 root root 315 Jul 13 16:18 use_all [root@mysql-server-01 multi_msb_mariadb-10_0_12]#
可以可以已經有3個節點了,我們登陸其中一個看看。
[root@mysql-server-01 multi_msb_mariadb-10_0_12]# ./n1 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 10.0.12-MariaDB-log MariaDB Server Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. node1 [localhost] {msandbox} ((none)) >
現在是不是開始愛上MySQL Sandbox了呢?那你還等什麼?心動就上吧!哈哈,就寫到這裡了。
mysql sandbox經典講義(因為被牆,故放在網盤給同學們下載)
http://pan.baidu.com/s/1sjLMJCx
參考資料
http://search.cpan.org/~gmax/MySQL-Sandbox-3.0.44/lib/MySQL/Sandbox.pm
About Me
........................................................................................................................ ● 本文作者:小麥苗,部分內容整理自網路,若有侵權請聯絡小麥苗刪除 ● 本文在itpub、部落格園、CSDN和個人微 信公眾號( xiaomaimiaolhr)上有同步更新 ● 本文itpub地址: http://blog.itpub.net/26736162 ● 本文部落格園地址: http://www.cnblogs.com/lhrbest ● 本文CSDN地址: https://blog.csdn.net/lihuarongaini ● 本文pdf版、個人簡介及小麥苗雲盤地址: http://blog.itpub.net/26736162/viewspace-1624453/ ● 資料庫筆試面試題庫及解答: http://blog.itpub.net/26736162/viewspace-2134706/ ● DBA寶典今日頭條號地址: http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826 ........................................................................................................................ ● QQ群號: 230161599 、618766405 ● 微 信群:可加我微 信,我拉大家進群,非誠勿擾 ● 聯絡我請加QQ好友 ( 646634621 ),註明新增緣由 ● 於 2019-08-01 06:00 ~ 2019-08-31 24:00 在西安完成 ● 最新修改時間:2019-08-01 06:00 ~ 2019-08-31 24:00 ● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解 ● 版權所有,歡迎分享本文,轉載請保留出處 ........................................................................................................................ ● 小麥苗的微店: https://weidian.com/s/793741433?wfr=c&ifr=shopdetail ● 小麥苗出版的資料庫類叢書: http://blog.itpub.net/26736162/viewspace-2142121/ ● 小麥苗OCP、OCM、高可用網路班: http://blog.itpub.net/26736162/viewspace-2148098/ ● 小麥苗騰訊課堂主頁: https://lhr.ke.qq.com/ ........................................................................................................................ 使用 微 信客戶端掃描下面的二維碼來關注小麥苗的微 信公眾號( xiaomaimiaolhr)及QQ群(DBA寶典)、新增小麥苗微 信, 學習最實用的資料庫技術。
........................................................................................................................ |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2655520/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 在容器環境搭建mysql備庫MySql
- Linux搭建PHP+MySQL+Apache環境LinuxPHPMySqlApache
- 在Mac下怎麼搭建MySQL環境?MacMySql
- 環境搭建
- Mac搭建PHP開發環境(PHP+Nginx+MySQL)MacPHP開發環境NginxMySql
- CentOS7搭建Java環境(JDK、MySQL和Tomcat)CentOSJavaJDKMySqlTomcat
- 生產環境中MySQL複製的搭建KPMySql
- 如何在 Kubernetes 環境中搭建 MySQL(四):使用 StMySql
- PyFlink 開發環境利器:Zeppelin Notebook開發環境
- 搭建lnmp環境LNMP
- 搭建gym環境
- Linuxg環境搭建Linux
- JDK環境搭建JDK
- Angular環境搭建Angular
- anaconda 環境搭建
- ReactNative環境搭建React
- swoft 環境搭建
- Flutter環境搭建Flutter
- 搭建Java環境Java
- Supervisor 環境搭建
- react環境搭建React
- FNA環境搭建
- FNA 環境搭建
- Maven 環境搭建Maven
- Dubbo環境搭建
- Vagrant 環境搭建
- LNMP 環境搭建LNMP
- OpenGL 環境搭建
- App環境搭建APP
- gogs環境搭建Go
- Kubernetes環境搭建
- mac搭建環境Mac
- python環境搭建Python
- keil環境搭建
- Windows環境下的Nginx環境搭建WindowsNginx
- window環境下testlink環境搭建(xammp)
- Linux 環境下 PHP 專案基礎執行環境搭建(PHP 7.3.6 + MySQL 8.0.16 + Nginx)LinuxPHPMySqlNginx
- LEMP環境搭建及配置(三)安裝MySQL5.6MySql