目錄
mycat登錄用戶的配置文件
mycat 連接用戶是在 $MYCAT_HOME/conf/server.xml裏面配置的。
<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License. - You
may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
- - Unless required by applicable law or agreed to in writing, software -
distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
License for the specific language governing permissions and - limitations
under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
<system>
<property name="nonePasswordLogin">0</property> <!-- 0爲需要密碼登陸、1爲不需要密碼登陸 ,默認爲0,設置爲1則需要指定默認賬戶-->
<property name="useHandshakeV10">1</property>
<property name="useSqlStat">0</property> <!-- 1爲開啓實時統計、0爲關閉 -->
<property name="useGlobleTableCheck">0</property> <!-- 1爲開啓全加班一致性檢測、0爲關閉 -->
<property name="sequnceHandlerType">2</property>
<!--<property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>-->
<!--必須帶有MYCATSEQ_或者 mycatseq_進入序列匹配流程 注意MYCATSEQ_有空格的情況-->
<property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>
<property name="subqueryRelationshipCheck">false</property> <!-- 子查詢中存在關聯查詢的情況下,檢查關聯字段中是否有分片字段 .默認 false -->
<!-- <property name="useCompression">1</property>--> <!--1爲開啓mysql壓縮協議-->
<!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--設置模擬的MySQL版本號-->
<!-- <property name="processorBufferChunk">40960</property> -->
<!--
<property name="processors">1</property>
<property name="processorExecutor">32</property>
-->
<!--默認爲type 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->
<property name="processorBufferPoolType">0</property>
<!--默認是65535 64K 用於sql解析時最大文本長度 -->
<!--<property name="maxStringLiteralLength">65535</property>-->
<!--<property name="sequnceHandlerType">0</property>-->
<!--<property name="backSocketNoDelay">1</property>-->
<!--<property name="frontSocketNoDelay">1</property>-->
<!--<property name="processorExecutor">16</property>-->
<property name="serverPort">8066</property>
<property name="managerPort">9066</property>
<!--
<property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property>
<property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
<!--分佈式事務開關,0爲不過濾分佈式事務,1爲過濾分佈式事務(如果分佈式事務內只涉及全局表,則不過濾),2爲不過濾分佈式事務,但是記錄分佈式事務日誌-->
<property name="handleDistributedTransactions">0</property>
<!--
off heap for merge/order/group/limit 1開啓 0關閉
-->
<property name="useOffHeapForMerge">0</property>
<!--
單位爲m
-->
<property name="memoryPageSize">64k</property>
<!--
單位爲k
-->
<property name="spillsFileBufferSize">1k</property>
<property name="useStreamOutput">0</property>
<!--
單位爲m
-->
<property name="systemReserveMemorySize">384m</property>
<!--是否採用zookeeper協調切換 -->
<property name="useZKSwitch">false</property>
<!-- XA Recovery Log日誌路徑 -->
<!--<property name="XARecoveryLogBaseDir">./</property>-->
<!-- XA Recovery Log日誌名稱 -->
<!--<property name="XARecoveryLogBaseName">tmlog</property>-->
<!--如果爲 true的話 嚴格遵守隔離級別,不會在僅僅只有select語句的時候在事務中切換連接-->
<property name="strictTxIsolation">false</property>
<property name="useZKSwitch">true</property>
</system>
<!-- 全局SQL防火牆設置 -->
<!--白名單可以使用通配符%或着*-->
<!--例如<host host="127.0.0.*" user="root"/>-->
<!--例如<host host="127.0.*" user="root"/>-->
<!--例如<host host="127.*" user="root"/>-->
<!--例如<host host="1*7.*" user="root"/>-->
<!--這些配置情況下對於127.0.0.1都能以root賬戶登錄-->
<!--
<firewall>
<whitehost>
<host host="1*7.0.0.*" user="root"/>
</whitehost>
<blacklist check="false">
</blacklist>
</firewall>
-->
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">TESTDB</property>
<!-- 表級 DML 權限設置 -->
<!--
<privileges check="false">
<schema name="TESTDB" dml="0110" >
<table name="tb01" dml="0000"></table>
<table name="tb02" dml="1111"></table>
</schema>
</privileges>
-->
</user>
<user name="user">
<property name="password">user</property>
<property name="schemas">TESTDB</property>
<property name="readOnly">true</property>
</user>
</mycat:server>
通過上面的配置文件可以看出:
- 可以通過user標籤就來配置要mycat的連接用戶;
- 可以在user標籤裏繼續嵌套property標籤來指定這個用戶的相關配置;
- 比如:password就是這個用戶的密碼,schemas就是這個用戶能夠連接的數據庫;
- 在user標籤下嵌套property標籤還可以完成這個用戶的權限配置。
- 權限配置舉例:readOnly是這個用戶連接中間件邏輯庫所具有的權限。true爲只讀,false爲讀寫都有,默認爲false。
- mycat配置了默認兩個用戶分別是test和user,分別設置了默認密碼、默認能連接的邏輯庫權限等;
- 如果想要新增加一個用戶,那麼直接添加一個user標籤就可以。在user標籤下指定這個心用戶的密碼和所能連接的數據庫。當然了,這裏的數據庫是虛擬的庫,是在schema.xml配置文件中配置的。多個schemas使用逗號隔開。
### 添加一個root用戶,用戶密碼爲root123456, 並且它有連接TESTDB,yukidb兩個邏輯庫的權限。
<user name="root">
<property name="password">root123456</property>
<property name="schemas">TESTDB,yukidb</property>
</user>
- 增加用戶之後需要重啓mycat配置纔會生效!!!
[root@myhost conf]# /usr/local/mycat/bin/mycat restart
Stopping Mycat-server...
Stopped Mycat-server.
Starting Mycat-server...
mycat用戶登錄
[root@myhost conf]# mysql -utest -ptest -P8066 -DTESTDB ### 不指定mycat服務端的ip地址
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)
[root@myhost conf]# mysql -uuser -puser -P8066 -DTESTDB ### 不指定mycat服務端的ip地址
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)
[root@myhost conf]# mysql -utest -ptest -h127.0.0.1 -P8066 -DTESTDB ### 本地連接mycat
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.8-mycat-1.4-beta-20150604171601 MyCat Server (OpenCloundDB) ###表明連接的是mycat
Copyright (c) 2000, 2016, 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> exit
[root@myhost conf]# mysql -uuser -puser -h127.0.0.1 -P8066 -DTESTDB ### 本地連接mycat
ysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.8-mycat-1.4-beta-20150604171601 MyCat Server (OpenCloundDB) ###表明連接的是mycat
Copyright (c) 2000, 2016, 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>
[root@myhost conf]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.61 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::2a6e:d4ff:fe88:c70c prefixlen 64 scopeid 0x20<link>
ether 28:6e:d4:88:c7:0c txqueuelen 1000 (Ethernet)
RX packets 3554658 bytes 1742639350 (1.6 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 305078 bytes 115890043 (110.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@myhost conf]# mysql -uuser -puser -h192.168.2.61 -P8066 -DTESTDB ### 遠程連接mycat
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.5.8-mycat-1.4-beta-20150604171601 MyCat Server (OpenCloundDB) ###表明連接的是mycat
Copyright (c) 2000, 2016, 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>
通過上面的操作可以看出:
- 在命令行連接mycat時,就算是本地連接,主機-h都不能省略,而且-h後面必須是ip,使用localhost會出錯。
查看mycat 默認數據庫、表(虛擬的邏輯庫和表)
mysql> show databases;
+----------+
| DATABASE |
+----------+
| TESTDB |
+----------+
1 row in set (0.00 sec)
mysql> use TESTDB;
Database changed
mysql> show tables;
+------------------+
| Tables in TESTDB |
+------------------+
| company |
| customer |
| customer_addr |
| employee |
| goods |
| hotnews |
| orders |
| order_items |
| travelrecord |
+------------------+
9 rows in set (0.00 sec)