Mycat1.5 installation, simple use

MyCAT can be regarded as an enterprise-level database of " MySQL " cluster, which is used to replace the expensive Oracle cluster. Behind it is the well-known product Cobar, which was once open sourced by Alibaba. The goal of MyCAT is to smoothly migrate existing stand-alone databases and applications to the "cloud" side at a low cost, so as to solve the data bottleneck problem in the case of data storage and rapid business scale growth.

1. Detailed deployment steps (install mysql first)

  (1) Use command line tools or graphical clients to connect to MYSQL and create three sharded databases for DEMO;
 CREATE database db1;
 CREATE database db2;
 CREATE database db3;

  (2) Modify my.inf to add the following statement, my.inf will usually be placed in /etc/my.cnf or /etc/mysql/my.cnf, set to Mysql case-insensitive, otherwise the table may not be found. to the problem.
 lower_case_table_names = 1

  (3) Unzip Mycat-server-1.3.0.2-20150105144205-linux.tar.gz to /usr/local/mycat

  (4) Unzip jdk-7u65-linux-i586.gz, configure environment variables

  (5) Create a mycat user and change the directory permissions to mycat
 useradd mycat
 chown -R mycat.mycat /usr/local/mycat

  (7) Modify the user password
 passwd mycat and
 enter:

  (8) 修改/usr/local/conf/schema.xml,URL、用户名、密码修改,其余不变
 <writeHost host="hostM1" url="10.1.176.104:3306" user="root"
                        password="www.com.workssys">

二、运行步骤详解

  (1) 进入 /usr/local/mycat/bin (默认数据端口为8066,管理端口为9066) 执行./mycat start

  (2) 进入logs目录,查看日志,如果wrapper.log 报错 java.net.BindException: Address already in use 杀掉正在执行的相关java进程
 ps -ef|grep java
 kill -9 xxx

三、使用步骤详解
  (1) 进入mysql bin目录/usr/local/mysql/bin/

  (2) 登录mysql 执行以下命令  注意:需要在安装mysql服务端执行mysql命令,使用navicat等工具分片可能出现问题
  mysql -utest -ptest -h10.1.176.104 -P8066 -DTESTDB
 (mycat的用户账号和授权信息是在conf/server.xml文件中配置)

  (3) 表创建测试:
 mysql> create table employee (id int not null primary key,name varchar(100),sharding_id int not null);
 Query OK, 0 rows affected (0.30 sec)

 mysql> explain create table employee (id int not null primary key,name varchar(100),sharding_id int not null);
 +-----------+------------------------------------------------------------------------------------------------+
 | DATA_NODE | SQL                                                                                            |
 +-----------+------------------------------------------------------------------------------------------------+
 | dn1       | create table employee (id int not null primary key,name varchar(100),sharding_id int not null) | 
 | dn2       | create table employee (id int not null primary key,name varchar(100),sharding_id int not null) | 
 +-----------+------------------------------------------------------------------------------------------------+
 2 rows in set (0.04 sec)


  (4) 客户端软件使用:navicat

 创建mycat新连接:ip:10.1.176.104,用户名:test,密码:test,端口:8066
 可看到TESTDB数据库下已创建表:employee

 打开db1,db2 数据库也可看到已创建表employee

  (5) 插入数据测试
 mysql> insert into employee(id,name,sharding_id) values(1,'leader us',10000);
 ERROR 2006 (HY000): MySQL server has gone away
 No connection. Trying to reconnect...
 Connection id:    6
 Current database: TESTDB

 Query OK, 1 row affected (0.03 sec)

 mysql> explain insert into employee(id,name,sharding_id) values(1,'leader us',10000);
 +-----------+-----------------------------------------------------------------------+
 | DATA_NODE | SQL                                                                   |
 +-----------+-----------------------------------------------------------------------+
 | dn1       | insert into employee(id,name,sharding_id) values(1,'leader us',10000) | 
 +-----------+-----------------------------------------------------------------------+
 1 row in set (0.00 sec)
 
  (6) 根据规则auto-sharding-long(主键范围)进行分片测试
 mysql> explain create table company(id int not null primary key,name varchar(100));
 +-----------+---------------------------------------------------------------------+
 | DATA_NODE | SQL                                                                 |
 +-----------+---------------------------------------------------------------------+
 | dn1       | create table company(id int not null primary key,name varchar(100)) | 
 | dn2       | create table company(id int not null primary key,name varchar(100)) | 
 | dn3       | create table company(id int not null primary key,name varchar(100)) | 
 +-----------+---------------------------------------------------------------------+
 3 rows in set (0.01 sec)

  (7) 三个分片上都插入了3条数据
 mysql> explain insert into company(id,name) values(1,'hp');
 +-----------+---------------------------------------------+
 | DATA_NODE | SQL                                         |
 +-----------+---------------------------------------------+
 | dn1       | insert into company(id,name) values(1,'hp') | 
 | dn2       | insert into company(id,name) values(1,'hp') | 
 | dn3       | insert into company(id,name) values(1,'hp') | 
 +-----------+---------------------------------------------+
 3 rows in set (0.00 sec)

  (8) 确认是分片存储
 
 mysql> select * from employee;
 +----+-----------+-------------+
 | id | name      | sharding_id |
 +----+-----------+-------------+
 |  2 | me        |       10010 | 
 |  4 | mydog     |       10010 | 
 |  1 | leader us |       10000 | 
 |  3 | mycat     |       10000 | 
 +----+-----------+-------------+
 4 rows in set (0.01 sec)

 mysql> explain select * from employee;
 +-----------+----------------------------------+
 | DATA_NODE | SQL                              |
 +-----------+----------------------------------+
 | dn1       | SELECT * FROM employee LIMIT 100 | 
 | dn2       | SELECT * FROM employee LIMIT 100 | 
 +-----------+----------------------------------+
 2 rows in set (0.00 sec)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326699803&siteId=291194637