程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MYSQL入門知識 >> MySQL::Sandbox

MySQL::Sandbox

編輯:MYSQL入門知識
 

這東西用起來還真簡單……可以快速地安裝一個或者一組mysql服務端程序。

安裝的時候使用root用戶,只需要一條命令就搞定:


# cpan MySQL::Sandbox
 

日常使用的時候,就不需要root權限了。

以用戶modify為例:


1) 建立一個存放mysql源程序的倉庫,並設置環境變量。
[modify@H209 ~]$ mkdir /home/modify/mysql
#這行指令應該要添加到 /home/modify/.bashrc文件中。
[modify@H209 ~]$ export SANDBOX_BINARY=/home/modify/mysql

2) 下載mysql5.6.10的安裝文件 (mysql-5.6.10-linux-glibc2.5-i686.tar.gz) 281.7M 到/home/modify/mysql目錄中。
[modify@H209 ~]$ ls /home/modify/mysql
mysql-5.6.10-linux-glibc2.5-i686.tar.gz


3) 創建第一個sandbox:
第一次需要解壓,所以時間會長一些
[modify@H209 ~]$ make_sandbox /home/modify/mysql/mysql-5.6.10-linux-glibc2.5-i686.tar.gz
unpacking /home/modify/mysql/mysql-5.6.10-linux-glibc2.5-i686.tar.gz
Executing low_level_make_sandbox --basedir=/home/modify/mysql/5.6.10 \
--sandbox_directory=msb_5_6_10 \
--install_version=5.6 \
--sandbox_port=5610 \
--no_ver_after_name \
--my_clause=log-error=msandbox.err
>>/tmp
<<5.6>>
The MySQL Sandbox, version 3.0.30
(C) 2006-2013 Giuseppe Maxia
installing with the following parameters:
upper_directory = /home/modify/sandboxes
sandbox_directory = msb_5_6_10
sandbox_port = 5610
check_port =
no_check_port =
datadir_from = script
install_version = 5.6
basedir = /home/modify/mysql/5.6.10
tmpdir =
my_file =
operating_system_user = modify
db_user = msandbox
remote_access = 127.%
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)

安裝之後的文件存在於 /home/modify/sandboxes/msb_5_6_10 目錄中。而且已經啟動了mysqld.
[modify@H209 ~]$ ls /home/modify/sandboxes/
clear_all msb_5_6_10 plugin.conf restart_all sandbox_action send_kill_all start_all status_all stop_all use_all

4)連接到sandbox:
[root@H209 modify]# /home/modify/sandboxes/msb_5_6_10/use
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.10 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 [localhost] {msandbox} ((none)) > select user();
+--------------------+
| user() |
+--------------------+
| msandbox@localhost |
+--------------------+
1 row in set (0.00 sec)


5) 再創建一個5.6.10的sandbox:
在第一次創建之後,源程序倉庫中已經有了一個名為5.6.10的目錄,其實就是從mysql-5.6.10-linux-glibc2.5-i686.tar.gz中解壓出來的:
[modify@H209 ~]$ ls /home/modify/mysql
5.6.10 mysql-5.6.10-linux-glibc2.5-i686.tar.gz

此時再創建5.6.10的sandbox,就比較簡單了:
[modify@H209 ~]$ make_sandbox 5.6.10
......
upper_directory = /home/modify/sandboxes
sandbox_directory = msb_5_6_10
sandbox_port = 5610
check_port =
no_check_port =
datadir_from = script
......
......
do you agree? ([Y],n) y

然後提示: /home/modify/sandboxes/msb_5_6_10 already exists.
不止這個目錄會沖突,mysqld使用的端口也會沖突,於是還要加一個參數:
[modify@H209 ~]$ make_sandbox 5.6.10 -- --check_port
......
upper_directory = /home/modify/sandboxes
sandbox_directory = msb_5_6_10_a
sandbox_port = 5611
.....

安裝目錄變成了 msb_5_6_10_a, 端口也加了1,變為5611,相當智能。

[modify@H209 ~]$ ls /home/modify/sandboxes/msb_5_6_10_a/
change_paths clear grants.mysql msb my.sandbox.cnf rescue_mysql_dump.sql send_kill status tmp USING
change_ports data load_grants my proxy_start restart start stop use

此目錄中的start, stop, restart用於啟動,關閉,重啟mysqld。


6) sbtool 此命令可以copy ,move, change port,delete某個sandbox。
詳情看文檔。

7) make_replication_sandbox 可以創建一主二從(當然這個結構也是可以用參數來調整的)。
[modify@H209 ~]$ make_replication_sandbox 5.6.10
installing and starting master  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved