Distributed database middleware MyCat

About MyCat
earlier article we mentioned, if the large amount of data, we need the data sub-library sub-table after points finish, originally present data in a database, now there are multiple databases, and like so :

 

 

So this time MyCat's role is distributed database middleware!

MyCat is an open source distributed database middleware that implements the MySQL protocol, the developer's eyes, he is a proxy database, we can even use MySQL client tools and command-line access MyCat.

MyCat now not only supports MySQL, and also supports MSSQL, Oracle, DB2, PostgreSQL and other mainstream database. Even such as MongoDB NoSQL is also supported.

Quick Start
set up separate read and write
engage MyCat, generally must first build a good read and write separation of MySQL, MySQL to read and write separation can refer to this article before Song Ge:

https://mp.weixin.qq.com/s/SC0OYM6yO_GxQh9DvSsnoQ
myCat installation
environment:

CentOS7
JDK1.8
myCat use Java development, therefore, run MyCat, must have a Java environment, configure the Java Runtime Environment that is relatively easy, there are many online information, I will not described in detail.

After installing the Java environment, first download MyCat:

http://dl.mycat.io/1.6.7.1/Mycat-server-1.6.7.1-release-20190213150257-linux.tar.gz wget
1
after the download is complete, the downloaded file to decompress it.

-zxvf myCat-Server-tar-1.6.7.1 Release-20,190,213,150,257-linux.tar.gz
1
after decompression is successful, there will be a mycat directory, enter the mycat / conf directory, to configure mycat:

First, let's configure schema.xml file:

 

 

First, in the schema specified logical library name, logic libraries refers to the physical library MyCat in the library, which does not store data, the data stored in MySQL's.
Logic database table configuration logic, configuration logic table, the need to specify Datanode node, refers Datanode location database stored in the
configuration name dataNode, dataNode dataHost specified physical library.
dataHost MySQL Host Configuration and from the position of the machine, login passwords and so on. Master and slave can be configured more.
After configuring the schema.xml, the following configuration server.xml.

server.xml is the main configuration MyCat login user name and password, and logic libraries need to operate.

 

 

Once configured, you can then start MyCat up.

Execution MyCat decompression mycat command in the bin directory under the directory, you can start MyCat

Start ./bin/mycat
1
if starts, prompting unable to create mycat.pid file, create a file on their own mycat.pid manually. After a successful start, you can connect a local MyCat, connections and MySQL, like, the only difference is the port number.

Before connecting MyCat, create db1, db2 and db3 three MySQL database in the physical library.

Use SQLyog connection:

 

 

You can also log on MyCat in cmd command line:

 

 

After a successful login, the MyCat window, run the following command to create the table:

create table t_user (id integer primary key,username varchar(255))
1
执行成功后,我们会发现物理库中出现了相应的表。
接下来,手动往各个物理库的物理表中存储一条数据,然后在 MyCat 窗口中查询:

 

 

这样就可以查询到 三个库中的三个表中的数据。

问题分析
整个过程不难,但是有的小伙伴在第一次配置的过程中还是容易出错,因此我这里还是来说两句,出错了要如何定位。

一般来说,配置 MyCat 出错,问题可能发生在两个阶段。第一个阶段就是客户端连接 MyCat 出错,第二个阶段就是 MyCat 连接 MySQL 出错。

无论你是使用 SQLyog 还是 Navicat ,我们在连接数据库的过程中,都可以先测试连接,很多人卡在这一步。

如果在测试连接的时候就连接不通,说明是 MyCat 的问题,这个时候检查步骤如下:

首先当然是查看日志信息,看能不能找出端倪
通过 jps 命令查看 mycat 是否成功启动
检查 server.xml 中配置是否正确,用户名密码是否输入正确
这是第一种可能的问题,第二种问题就是测试连接没问题,但是测试完后,却连接不上。反映到 Navicat 上,就是测试连接没问题,测完之后,点击连接名要打开连接时,Navicat 就崩了,出现这个问题一般是 MyCat 在连接 MySQL 出问题了,这个时候就要去检查 schema.xml 文件中关于 MySQL 主机和从机的配置是否正确,数据库地址是否正确,用户名密码是否正确。

结语
好了,本文主要简单介绍了下 MyCat 的安装问题,下篇文章我们来看 MyCat 中的分片规则问题。

参考资料:

MyCat 官方文档
---------------------
作者:_江南一点雨
来源:CSDN
原文:https://blog.csdn.net/u012702547/article/details/93966679
版权声明:本文为博主原创文章,转载请附上博文链接!

Guess you like

Origin www.cnblogs.com/wmqBlog/p/11115493.html