Mycat下载可以到官网下载也可以到github上下载
下载路径:
官方网站:http://www.mycat.org.cn/
github地址https://github.com/MyCATApache
Mycat安装
MyCat安装,需要安装jdk
上传并解压
把MyCat的压缩包上传到linux服务器,并且解压
安装步骤
我的安装在/usr/local
首先把你的进入你MyCat压缩包的目录下(我的在/opt/install)
[root@localhost local]# cd /opt/install
[root@localhost install]# tar -xvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local usr/local
//解压并复制到/usr/local
[root@localhost install]# cd /usr/local
[root@localhost local]# ls
bin etc games include lib lib64 libexec mycat sbin share src
[root@localhost local]# cd mycat
[root@localhost mycat]# cd bin
[root@localhost bin]# ./mycat -start //启动mycat
Usage: ./mycat { console | start | stop | restart | status | dump }
[root@localhost mycat]# pwd
/usr/local/mycat
[root@localhost mycat]# cd conf
[root@localhost conf]# vi server.xml //这一步可以省略
<user name="root">
<!--默认用户:root 密码:123456-->
<property name="password">123456</property>
<property name="schemas">TESTDB</property>
</user>
<!--默认用户:user 密码:user-->
<user name="user">
<property name="password">user</property>
<property name="schemas">TESTDB</property>
<property name="readOnly">true</property>
</user>
mysql> create table tb_user(id int,name varchar(30),password varchar(30)); ERROR 1495 (HY000): User readonly
如果出现这个错可以这样修改,或者用root登录
注意:
1、这里配置的是可以连接主库的两个用户
用户:root 密码:oldboy 给予此用户test数据库增删改查的权限。
用户:user 密码:oldboy 给予此用户test数据库读的权限。
2、这里的TESTDB,不一定是你数据库上的真实库名,可以任意指定,只要接下来和schema.xml的配置文件的库名统一即可
[root@localhost conf]# cd ..
root@localhost mycat]# cd bin
[root@localhost bin]# ./mycat restart //重启mycat
Stopping Mycat-server...
Mycat-server was not running.
[root@localhost bin]# firewall-cmd --permanent --add-port=8066/tcp //mycat默认端口8066,打开8066端口
Warning: ALREADY_ENABLED: 8066:tcp
success
[root@localhost bin]# firewall-cmd --reload //重新加载
success
[root@localhost conf]# vi schema.xml
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="localhost:3306" user="root"
password="admin">
<!-- can have multi read hosts -->
<readHost host="hostS2" url="192.168.1.200:3306" user="root" password="xxx" />
</writeHost>
<writeHost host="hostS1" url="localhost:3316" user="root"
password="123456" />
<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
</dataHost>[root@localhost bin]# mysql -uuser -puser -P8066 -h192.168.19.60
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 5
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)Copyright (c) 2000, 2018, 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> quit;
也可以连接mysql的图形化工具了:如图
启动
/usr/local/mycat/bin ./mycat start 启动
/usr/local/mycat/bin ./mycat stop 停止
/usr/local/mycat/bin ./mycat restart 重启