Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9572
  • 博文数量: 5
  • 博客积分: 176
  • 博客等级: 入伍新兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-08 18:25
文章分类

全部博文(5)

文章存档

2011年(5)

我的朋友

分类: Mysql/postgreSQL

2011-10-20 13:50:02

  As developers, we often need to check some problems or features with various MySQL options, or check them on a few different versions. So we need to change MySQL's config file often and run many MySQL servers of different versions at the same machines. That is very boring and inconvenient. Fortunately , we have 'MySQL Test' platform which can do the boring job for us and make the work simple.

* Running MySQL Test Cases

  MySQL test platform and its test cases are in 'mysql-test' directory.
  1.  cd mysql-test; 
  2.  ./mysql-test-run --force # Run all the test cases
  3.  ./mtr bug39002 # Run 'bug39002' only, 'mtr' is a symbolic link of 'mysql-test-run'
  If some special mysqld options are necessary, you can use '--mysqld' option to set them.
  1. ./mtr my_events --mysqld='--event-scheduler=disabled'

* Writing Queries In Test Cases
  The easiest way of checking some stuff of MySQL server is to write queries in a test case file and let MySQL test to help us to run a server and execute the queries.
 
  Write following queries in 'mysql-test/t/my_testcase.test':
  1.  CREATE TABLE t1(int 1);
  2.   INSERT INTO t1 VALUES(1),(2),(3);
  3.   SELECT * FROM t1;
  Execute the test case
  1. ./mtr my_testcase

* Setting A Single Server Up
  If some stuff can only be done through real clients(Web server, mysql etc.), then we have to setup a server. That can be done by running a test case for a long time. We usually can let the test case sleep. It is a little bit tricky, but very simple.

  Write following code in 'mysql-test/t/my_testcase.test':
  1.  sleep 100000; # sleep the test case 100,000 seconds
Execute the test case
  1.  ./mtr my_testcase
  2.  =============================================================================

     TEST                                      RESULT   TIME (ms) or COMMENT
     --------------------------------------------------------------------------

     worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 13000..13009


  From the output, we can know port from 13000 to 13009 are reserved for MySQL servers. The first server is on port 13000 and second server will follow the first one if existing. In this case, there is only one server is set up. Now we can connect to the server from any client. E.g.
  1.  client/mysql -u root -P 13000 -h 127.0.0.1

* Running A Server With Binary Log
  If you want to setup the server with binary log, You need to write a test case to 'mysql-test/suite/binlog/t' directory with below code:
  1.  source include/have_log_bin.inc;
  2.  sleep 100000;
  Following include files can be used to replace 'have_log_bin.inc' for different binary log format:
  1.  source include/have_binlog_format_row.inc;       # Use row format
  2.  source include/have_binlog_format_mixed.inc;     # Use mixed format
  3.  source include/have_binlog_format_statement.inc; # Use statement format

* Running A Few Servers For Replication
  If you want to setup a master and a slave, you can add a test case to 'mysql-test/suite/rpl/t' directory with following code:

  1.  source include/master-slave.inc;
  2.  source include/have_binlog_format_mixed.inc;
  sleep 100000;
  Following include files can be used to replace 'have_binlog_format_mixed.inc' for logging data in ROW or STATEMENT format:
  1.  source include/have_binlog_format_row.inc;       # Use row format
  2.  source include/have_binlog_format_statement.inc; # Use statement format
  The include file below is an alternative of 'master-slave.inc' if you want to setup replication with more complex topologies. E.g. circular replication or cascading replication.
  1.  source include/rpl_init.inc;
 
阅读(408) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~