Mycat of --Mycat interconnection with MySQL 8.x

How do you implement the teachings Mycat and MySQL 8.x interconnection, that is to achieve Mycat connection MySQL 8.x database, while implemented using MySQL 8.x command line connection Mycat.

1. Create a MySQL user

First, create a user in MySQL MySQL8.x Mycat connected, as shown below.

CREATE USER 'mycat'@'192.168.175.%' IDENTIFIED BY 'mycat';
ALTER USER 'mycat'@'192.168.175.%' IDENTIFIED WITH mysql_native_password BY 'mycat'; 
GRANT SELECT, INSERT, UPDATE, DELETE  ON *.* TO 'mycat'@'192.168.175.%';
FLUSH PRIVILEGES;

2. schema.xml configuration file

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">

	<schema name="shop" checkSQLschema="false" sqlMaxLimit="1000">
		<table name="order_master" primaryKey="order_id" dataNode = "ordb"/>
		<table name="order_detail" primaryKey="order_detail_id" dataNode = "ordb"/>
		<table name="order_cart" primaryKey="cart_id" dataNode = "ordb"/>
		<table name="order_customer_addr" primaryKey="customer_addr_id" dataNode = "ordb"/>
		<table name="region_info" primaryKey="region_id" dataNode = "ordb"/>
		<table name="serial" primaryKey="id" dataNode = "ordb"/>
		<table name="shipping_info" primaryKey="ship_id" dataNode = "ordb"/>
		<table name="warehouse_info" primaryKey="w_id" dataNode = "ordb"/>
		<table name="warehouse_proudct" primaryKey="wp_id" dataNode = "ordb"/>
		
		<table name="product_brand_info" primaryKey="brand_id" dataNode = "prodb"/>
		<table name="product_category" primaryKey="category_id" dataNode = "prodb"/>
		<table name="product_comment" primaryKey="comment_id" dataNode = "prodb"/>
		<table name="product_info" primaryKey="product_id" dataNode = "prodb"/>
		<table name="product_pic_info" primaryKey="product_pic_id" dataNode = "prodb"/>
		<table name="product_supplier_info" primaryKey="supplier_id" dataNode = "prodb"/>
		
		<table name="customer_balance_log" primaryKey="balance_id" dataNode = "custdb"/>
		<table name="customer_inf" primaryKey="customer_inf_id" dataNode = "custdb"/>
		<table name="customer_level_inf" primaryKey="customer_level" dataNode = "custdb"/>
		<table name="customer_login" primaryKey="customer_id" dataNode = "custdb"/>
		<table name="customer_login_log" primaryKey="login_id" dataNode = "custdb"/>
		<table name="customer_point_log" primaryKey="point_id" dataNode = "custdb"/>
		
	</schema>
	 
	<dataNode name="ordb" dataHost="binghe152" database="order_db" />
	<dataNode name="prodb" dataHost="binghe153" database="product_db" />
	<dataNode name="custdb" dataHost="binghe154" database="customer_db" />

	
	<dataHost name="binghe152" maxCon="1000" minCon="10" balance="1"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<writeHost host="binghe52" url="192.168.175.152:3306" user="root" password="root"/>
	</dataHost>
	
	<dataHost name="binghe153" maxCon="1000" minCon="10" balance="1"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<writeHost host="binghe53" url="192.168.175.153:3306" user="root" password="root"/>
	</dataHost>
	
	<dataHost name="binghe154" maxCon="1000" minCon="10" balance="1"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<writeHost host="binghe54" url="192.168.175.154:3306" user="root" password="root"/>
	</dataHost>
	
</mycat:schema>

3. Configure server.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
	<system>
		<property name="useHandshakeV10">1</property>
        <property name="defaultSqlParser">druidparser</property>
		<property name="serverPort">3307</property>
		<property name="managerPort">3308</property>
		<property name="nonePasswordLogin">0</property>
		<property name="bindIp">0.0.0.0</property>
		<property name="charset">utf8mb4</property>
		<property name="frontWriteQueueSize">2048</property>
		<property name="txIsolation">2</property>
		<property name="processors">2</property>
		<property name="idleTimeout">1800000</property>
		<property name="sqlExecuteTimeout">300</property>
		<property name="useSqlStat">0</property>
		<property name="useGlobleTableCheck">0</property>
		<property name="sequenceHandlerType">2</property>
		<property name="defaultMaxLimit">1000</property>
		<property name="maxPacketSize">104857600</property>
	</system>
	
	<user name="mycat" defaultAccount="true">
		<property name="usingDecrypt">1</property>
		<property name="password">cTwf23RrpBCEmalp/nx0BAKenNhvNs2NSr9nYiMzHADeEDEfwVWlI6hBDccJjNBJqJxnunHFp5ae63PPnMfGYA==</property>
		<property name="schemas">shop</property>
	</user>
</mycat:server>

Note: When you need to use the mysql command to connect MySQL 8.x Mycat, you must configure the following options in the server.xml file system label.

<property name="useHandshakeV10">1</property>
<property name="defaultSqlParser">druidparser</property>

Otherwise, MySQL 8.x command of mysql connection Mycat fail.

Password tag value in tag registration Mycat user password, this value is provided using encryption based Mycat plaintext encrypted password. Such mounting io.mycat.util.DecryptUtil present in myCat class Mycat-server-xxx-release.jar lib directory under the directory, the password can be encrypted using the following command.

java java -cp /usr/local/mycat/lib/Mycat-server-xxx-release.jar io.mycat.util.DecryptUtil 0:mycat:mycat

Wherein 0: mycat: mycat operating parameters Jar packet 0 indicates a ciphertext password application to connect myCat; myCat behalf of a first user name myCat connection, i.e. for which user password encryption; second myCat representatives need encrypted password.

The results shown below encrypted data

cTwf23RrpBCEmalp/nx0BAKenNhvNs2NSr9nYiMzHADeEDEfwVWlI6hBDccJjNBJqJxnunHFp5ae63PPnMfGYA==

I.e., the value of the password attribute of the user label.

If the manner described above for the password encryption Mycat connection, you need to configure the following options in the user tag, or can not properly connected Mycat

<property name="usingDecrypt">1</property>

4. Connect Mycat

MySQL 8.x using the mysql command connects Mycat, as shown below.

[root@binghe151 ~]# mysql -umycat -pmycat -h192.168.175.151 -P3307 --default-auth=mysql_native_password
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-xxx-release-20200228205020 MyCat Server (OpenCloudDB)

Copyright (c) 2000, 2019, 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>

The use MySQL8.x mysql connection command Mycat, be noted that to add --default-auth = mysql_native_password option mysql command later.

Next, the logical view database and logic table under the myCat, as shown below.

mysql> SHOW DATABASES;
+----------+
| DATABASE |
+----------+
| shop     |
+----------+
1 row in set (0.00 sec)

mysql> USE shop;
Database changed
mysql> SHOW TABLES;
+-----------------------+
| Tables in shop        |
+-----------------------+
| customer_balance_log  |
| customer_inf          |
| customer_level_inf    |
| customer_login        |
| customer_login_log    |
| customer_point_log    |
| order_cart            |
| order_customer_addr   |
| order_detail          |
| order_master          |
| product_brand_info    |
| product_category      |
| product_comment       |
| product_info          |
| product_pic_info      |
| product_supplier_info |
| region_info           |
| serial                |
| shipping_info         |
| warehouse_info        |
| warehouse_proudct     |
+-----------------------+
21 rows in set (0.00 sec)

mysql> SELECT product_id, product_code, product_name FROM product_info LIMIT 10;
+------------+------------------+---------------------------------------+
| product_id | product_code     | product_name                          |
+------------+------------------+---------------------------------------+
|          1 | 3700000000000001 | [Columbia]打底裤示例商品-1            |
|          2 | 3600000000000001 | [TheNorthFace]小脚裤示例商品-1        |
|          3 | 3500000000000001 | [李宁]九分裤示例商品-1                |
|          4 | 3400000000000001 | [LOWA]哈伦裤示例商品-1                |
|          5 | 3300000000000001 | [JACK&JONES]连体裤示例商品-1          |
|          6 | 3200000000000001 | [诺诗兰]牛仔裤示例商品-1              |
|          7 | 3100000000000001 | [骆驼]休闲裤示例商品-1                |
|          8 | 3000000000000001 | [金狐狸]风衣示例商品-1                |
|          9 | 2900000000000001 | [Columbia]小西装示例商品-1            |
|         10 | 2800000000000001 | [李宁]外套示例商品-1                  |
+------------+------------------+---------------------------------------+
10 rows in set (0.01 sec)

At this point, it is configured over, is not it simple? Like it a point like it! !

发布了1322 篇原创文章 · 获赞 2046 · 访问量 518万+

Guess you like

Origin blog.csdn.net/l1028386804/article/details/104571587