mycat 安装和简单应用
一、mycat 概述
mycat用于数据库的分库分表,本文以数据库mysql-8.0.31为例。mycat主要用“逻辑库、逻辑表”来管理各个物理节点主机的数据库和表。mycat需要配置“逻辑库、逻辑表(需要配置分库分表规则rule,核心内容)、逻辑节点、逻辑主机、登录mycat的用户名和密码”。schema.xml,主要配置了“逻辑库、逻辑表、逻辑节点、逻辑主机(关联逻辑节点和真实主机,以及真实主机登录mysql的用户名和密码)”。sever.xml,主要配置mycat登录的用户名和密码。rule.xml, 主要配置了分库分表的规则,注意在function中关联的文件。
二、mycat的安装和使用
mycat的安装和使用(mycat1.6.7.3) == mycat 安装 == --、安装说明: -- mycat 前置条件: -- 必须安装jdk; -- 可以用版本: jdk11、jdk8 -- mycat: -- 安装目录: ../mycat_install; -- 版本:Mycat-server-1.6.7.3-release-20190923113828-win.tar -- mysql 版本: 8.0.31 -- jdk 版本: (选用)jdk-11.0.17_windows-x64_bin.zip; jdk-8u351-windows-x64.exe -- jdk11_install = D:\tools\web\java\jdk\jdk11\bin\java -- 下载连接: -- mycat_download: http://www.mycat.org.cn/mycat1.html -- mysql_download: https://dev.mysql.com/downloads/mysql/ -- mysql_connector_j_download: https://dev.mysql.com/downloads/connector/j/ -- 说明: 由于mycat 的jdbc版本比较旧,所以需要用新版本替换旧版本; mycat 安装跟目录为 ../mycat_install -- 替换位置: ../mycat_install/lib/mysql-connector-java-5.1.35.jar; -- 将 mysql-connector-j-8.0.31.jar 改名为 mysql-connector-java-8.0.31.jar; -- ../mycat_install/lib/mysql-connector-java-5.1.35.jar 替换为 mysql-connector-java-8.0.31.jar; -- select operating system: platform independent -- version: mysql-connector-j-8.0.31.tar.gz; mysql-connector-j-8.0.31.zip -- mycat安装(解压式安装) -- 解压文件: Mycat-server-1.6.7.4-release-20200105164103-win.tar; 安装目录为 mycat_install = D:\tools\web\db\mysql\plugins\mycat1676 -- 配置mycat的系统环境变量: -- mycat_install=D:\tools\web\db\mysql\plugins\mycat1676 -- path=%mycat_install%\bin; -- 配置文件wrapper.conf: ../mycat_install/conf/wrapper.conf # wrapper.java.command=java # wrapper.java.command=jdk_install\bin\java # wrapper.java.command=C:\Program Files\Java\jdk1.8.0_351\bin\java wrapper.java.command=D:\tools\web\java\jdk\jdk11\bin\java == mycat 使用 == -- 一些说明: -- 在mycat和数据库中, 英文大小写敏感; -- mycat登录的账户admin和密码211224ln, 见配置文件“plugins\mycat\mycat1600\win\mycat_config_examples\mycat1673\conf\server.xml” ; <user name="admin"> <property name="password">211224ln</property> <property name="schemas">MYCAT</property> </user> -- 表和数据 CREATE TABLE IF NOT EXISTS TBL_INFO( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `i_name` VARCHAR(20), PRIMARY KEY(`id`) )ENGINE=INNODB; INSERT INTO TBL_INFO(id, i_name) VALUES(88, "laohu"); INSERT INTO TBL_INFO(id, i_name) VALUES(188, "tuzi"); -- mycat 配置 -- mycat配置内容: 逻辑库/逻辑表/逻辑节点/逻辑主机; 位置:plugins\mycat\mycat1600\win\mycat_config_examples\mycat1673\conf\schema.xml -- 逻辑库: 在mycat中,显示的虚拟库名; -- 逻辑表: 在mycat中,显示的虚拟库中的虚拟表名; -- 逻辑节点: 将“逻辑节点”和“逻辑主机”关联; -- 逻辑主机: 将“逻辑主机”和“真实主机”关联; 并配置在“真实主机”登录mysql的用户名和密码; -- mycat配置内容: mycat登录用户和密码; 位置:plugins\mycat\mycat1600\win\mycat_config_examples\mycat1673\conf\server.xml <user name="admin"> <property name="password">211224ln</property> <property name="schemas">MYCAT</property> </user> -- mycat配置内容: 分库分表规则; 位置:plugins\mycat\mycat1600\win\mycat_config_examples\mycat1673\conf\rule.xml -- 分片规则,重点研究,认真研读 -- 关联关系: -- (1) (schema.xml)<table rule="auto-sharding-long" /> ==> rule.xml的 <tableRule name="auto-sharding-long"> <rule> <columns>id</columns> ==> rule.xml的 <algorithm>rang-long</algorithm> </rule> </tableRule> -- (2) <function name="rang-long" class="io.mycat.route.function.AutoPartitionByLong"> <property name="mapFile">autopartition-long.txt</property> ==> autopartition-long.txt </function> -- (3) autopartition-long.txt = plugins\mycat\mycat1600\win\mycat_config_examples\mycat1673\conf\autopartition-long.txt -- mycat 服务: -- 安装服务: G:\tmpWorkspaces>mycat install wrapper | Mycat-server installed. -- 开启服务: G:\tmpWorkspaces>mycat start wrapper | Starting the Mycat-server service... wrapper | Waiting to start... wrapper | Mycat-server started. -- 关闭服务: G:\tmpWorkspaces>mycat stop wrapper | Stopping the Mycat-server service... wrapper | Mycat-server stopped. -- 卸载服务: G:\tmpWorkspaces>mycat remove wrapper | Mycat-server removed. -- 登录和退出 mycat: -- 登录mycat: mysql -h mycat_install_host_ip -P 8066 -uadmin -p G:\tmpWorkspaces>mysql -h 10.10.10.12 -P 8066 -uadmin -p Enter password: ******** -- 退出mycat: mysql> \q Bye -- mycat中操作数据库: mysql> mysql> show databases; +----------+ | DATABASE | +----------+ | MYCAT | +----------+ 1 row in set (0.01 sec) mysql> mysql> use MYCAT; Database changed mysql> mysql> CREATE TABLE IF NOT EXISTS TBL_INFO( -> `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, -> `i_name` VARCHAR(20), -> PRIMARY KEY(`id`) -> )ENGINE=INNODB; Query OK, 0 rows affected (0.32 sec) OK! mysql> mysql> INSERT INTO TBL_INFO(id, i_name) VALUES(88, "laohu"); Query OK, 1 row affected (0.34 sec) OK! mysql> INSERT INTO TBL_INFO(id, i_name) VALUES(188, "tuzi"); Query OK, 1 row affected (0.01 sec) OK! mysql> select * from TBL_INFO; +------+--------+ | id | i_name | +------+--------+ | 88 | laohu | | 188 | tuzi | +------+--------+ 2 rows in set (0.11 sec) -- mycat 完整操作流程: -- mycat服务安装: G:\tmpWorkspaces>mycat install wrapper | Mycat-server installed. -- mycat服务开启: G:\tmpWorkspaces>mycat start wrapper | Starting the Mycat-server service... wrapper | Waiting to start... wrapper | Mycat-server started. -- mycat登录: G:\tmpWorkspaces>mysql -h 10.10.10.12 -P 8066 -uadmin -p Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.29-mycat-1.6.7.3-release-20190923113828 MyCat Server (OpenCloudDB) Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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. -- mycat操作数据库: mysql> mysql> show databases; +----------+ | DATABASE | +----------+ | MYCAT | +----------+ 1 row in set (0.01 sec) mysql> mysql> use MYCAT; Database changed mysql> mysql> CREATE TABLE IF NOT EXISTS TBL_INFO( -> `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, -> `i_name` VARCHAR(20), -> PRIMARY KEY(`id`) -> )ENGINE=INNODB; Query OK, 0 rows affected (0.32 sec) OK! mysql> mysql> INSERT INTO TBL_INFO(id, i_name) VALUES(88, "laohu"); Query OK, 1 row affected (0.34 sec) OK! mysql> INSERT INTO TBL_INFO(id, i_name) VALUES(188, "tuzi"); Query OK, 1 row affected (0.01 sec) OK! mysql> select * from TBL_INFO; +------+--------+ | id | i_name | +------+--------+ | 88 | laohu | | 188 | tuzi | +------+--------+ 2 rows in set (0.11 sec) -- mycat退出: mysql> mysql> \q Bye -- mycat服务关闭: G:\tmpWorkspaces> G:\tmpWorkspaces>mycat stop wrapper | Stopping the Mycat-server service... wrapper | Mycat-server stopped. -- mycat服务卸载: G:\tmpWorkspaces> G:\tmpWorkspaces> G:\tmpWorkspaces>mycat remove wrapper | Mycat-server removed. G:\tmpWorkspaces> G:\tmpWorkspaces>
三、图片实例
1、mycat服务的安装和开启、登录mycat
2、mycat操作数据库1:创建表
3、mycat 数据库操作2:插入数据和查询
4、mycat退出登录、关闭服务、卸载服务
标签:--,wrapper,server,mysql,mycat,安装,id From: https://www.cnblogs.com/lnlidawei/p/16832688.html