• mysql04


    mycat 数据库中间件

    安装jdk 1.8 , mycat-server-1.6

    rpm -ivh jdk-8u144-linux-i586.rpm
    tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

    cd mycat

    内存不足

    1 vi wrapper.conf
    2 
    3 wrapper.java.additional.5=-XX:MaxDirectMemorySize=512M
    4 wrapper.java.additional.10=-Xmx512M
    5 wrapper.java.additional.11=-Xms512M

    修改server.xml 和 schema.xml 使用户名和密码一致

    启动mycat

    cd bin

    ./mycat console

    mycat 读写分离

    环境搭建

    mycat 192.168.239.140

    mysql 主节点 192.168.239.141

    mysql 从节点 192.168.239.145

    主从搭建

    问题排除:从节点Slave_Io_Running NO

    Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

     master

    >show master status;

    1 change master to master_host='192.168.239.141' , master_port=3306,master_user='repl',
    master_password='repl',master_log_file='relay-bin.000008',master_log_pos=402;

    start slave;

    show slave statusG;

    报错 binlog truncated in the middleof event,位置点不对

    1 mysqlbinlog relay-bin.000008 >1.txt
    2 
    3 vi 1.txt

    得到位置为154

    1 stop slave
    2 
    3 change master to master_host='192.168.239.141' , master_port=3306,master_user='repl',master_password='repl',master_log_file='relay-bin.000008',master_log_pos=154;
    4 
    5 start slave;

    创建用户

    1  create user 'mycat'@'%' identified by 'mycat';
    2 
    3 grant all on *.* to 'mycat'@'%';

    mycat

    cd conf

    vi schema.xml

     1 <?xml version="1.0"?>
     2 <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
     3 <mycat:schema xmlns:mycat="http://io.mycat/">
     4 
     5         <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
     6 
     7                 <table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />
     8                 <table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
    8          <table name="mytable" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3"/>   9 <table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" /> 10 <table name="hotnews" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2,dn3" 11 rule="mod-long" /> 12 <table name="employee" primaryKey="ID" dataNode="dn1,dn2" 13 rule="sharding-by-intfile" /> 14 <table name="customer" primaryKey="ID" dataNode="dn1,dn2" 15 rule="sharding-by-intfile"> 16 <childTable name="orders" primaryKey="ID" joinKey="customer_id" 17 parentKey="id"> 18 <childTable name="order_items" joinKey="order_id" 19 parentKey="id" /> 20 </childTable> 21 <childTable name="customer_addr" primaryKey="ID" joinKey="customer_id" 22 parentKey="id" /> 23 </table> 24 25 </schema> 26 <dataNode name="dn1" dataHost="localhost1" database="db1" /> 27 <dataNode name="dn2" dataHost="localhost1" database="db2" /> 28 <dataNode name="dn3" dataHost="localhost1" database="db3" /> 29 30 <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" 31 writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> 32 <heartbeat>select user()</heartbeat> 33 34 <writeHost host="hostM1" url="192.168.239.141:3306" user="mycat" 35 password="mycat"> 36 37 <readHost host="hostS2" url="192.168.239.145:3306" user="mycat" password="mycat" /> 38 </writeHost> 39 40 </dataHost> 41 </mycat:schema>

    主从库中设置数据库

    create database db1;

    create database db2;

    create database db3;

    mycat 启动

    ./mycat console

    copy  192.168.239.145

    1 mysql -uroot -proot -h192.168.239.140 -P8066    
    2 
    3 use TESTDB
    4 
    5 create table mytable (id int primary  key ,name varchar(10));
    6 
    7 insert into mytable(id,name) values (1,'zhangsan');

    explain insert into mytable(id,name) values (1,'zhangsan');

    select * from mytable;

    此是应是连接从库,查看日志

    cd /usr/local/mycat/logs

    cat wrapper.log |grep mytable

    cat wrapper.log |grep mytable


    INFO | jvm 1 | 2019/08/28 04:14:55 | 2019-08-28 04:14:55,619 [WARN ][$_NIOREACTOR-0-RW] ServerConnection [id=1, schema=TESTDB, host=192.168.239.145, user=root,txIsolation=3, autocommit=true, schema=TESTDB]create table mytable (id int primary key ,name varchar(10))

    查询缓存

    MySQL 的查询缓存是MySQL 内置的一种缓存机制,可以针对 sql 进行缓存。
    对于 sql 的匹配规则非常简单,就是字符串的比较,只要字符串相同,那么就认为是同一个查询。
    一旦开启了查询缓存,那么对所有的 sql 查询
    默认都是开启的。我们会有很多变化的数据,其实是不希望开启查询缓存的,即在 sql 中加入 sql_no_cache
    需要注意的,比如在 sql 中使用了 now()这样的函数, MySQL 是不会给我们缓存的

    查询是否开启缓存
    >show variables like '%query%';

    开启查询缓存的方式也非常简单,在 my.cnf 配置文件中设置上面的关于查询缓存的变量就可以

    变量含义
    query_caceh_type 是否开启查询缓存 ,
    0 表示不开启查询缓存
    1 表示始终开启查询缓存(不要缓存使用 sql_no_cache)
    2 表示按需开启查询缓存 (需要缓存使用 sql_cache)

    query_cache_size 给缓存分配的最大内存空间

    对于查询缓存的一些操作。
    FLUSH QUERY CACHE; // 清理查询缓存内存碎片。
    RESET QUERY CACHE; // 从查询缓存中移出所有查询。
    FLUSH TABLES; //关闭所有打开的表,同时该操作将会清空查询缓存中的内容。

     完

  • 相关阅读:
    ios 写项目的时候遇到的问题及解决方案(1)
    思绪锦集
    iOS学习-----真机测试过程
    StackOverflow程序员推荐的几本书籍
    关于算法学习的重要性
    程序的灵魂-算法
    C++ 之 const 随笔记
    Foundation 框架之——NSString、NSMutableString
    Objective-C之NSString和NSMutableString
    Objective-C之集合对象(NSSet,NSMutableSet,NSIndexSet)
  • 原文地址:https://www.cnblogs.com/quyangyang/p/11427041.html
Copyright © 2020-2023  润新知