zoukankan      html  css  js  c++  java
  • 从零开始mycat实验环境搭建

    版本说明

    本机:

    jdk 8

    使用IntelliJ IDEA调试MyCAT 1.6 release

    主机一:droplet  CentOS 7.5 x86_64

    MyCAT 1.6 release

    OpenJDK 1.8

    MySQL-Server 5.7

    主机二:bandwagon CentOS 6.8 i686

    MySQL-Client 5.6

    实验过程

    0. 调整时区
    timedatectl set-local-rtc 1
    timedatectl set-timezone Asia/Shanghai

    1. MySQL 5.7 安装

    为加快速度,使用二进制安装

    规划了三个实例

    [karenyin@centos-s-karenyin mysql_data]$ tree -L 1
    .
    ├── 10010
    ├── 10011
    ├── 10012
    ├── conf
    └── start_mysql.sh

     

    wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar
    rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
    rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
    rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
    rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
    yum install -y libaio
    rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm
    
    mysqld --defaults-file='/home/karenyin/mysql_data/conf/10010.cnf' --initialize-insecure
    mysql -u -S 你在后面再接个参数, 跳过加载权限表 可以进去改个密码,再退出来。
    --skip-grant-tables
    
    mysql --defaults-file='/home/karenyin/mysql_data/conf/10010.cnf'
    create database TESTDB;
    CREATE USER 'karenyin'@'%' IDENTIFIED BY "123456";
    grant all privileges on db_music.* to 'karenyin'@'%' identified by "123456";
    CREATE USER 'karenyin'@'localhost' IDENTIFIED BY "123456";
    grant all privileges on db_music.* to 'karenyin'@'localhost' identified by "123456";
    flush privileges;
    CREATE USER "root"@"%" IDENTIFIED BY "123456";
    grant all privileges on *.* to 'root'@'%' identified by "123456" with grant option;
    flush privileges;
    show grants; 查看select user()的授权情况
    show grants for karenyin;
    show grants for karenyin@'%';
    View Code

    sed 's/10010/10011/g' -i 10011.cnf

    sed 's/10010/10011/g' -i 10012.cnf

    MySQL配置文件可参考(老叶茶馆my.cnf生成器):

    [client]
    port    = 10010
    socket    = /home/karenyin/mysql_data/10010/mysql.sock
    
    [mysql]
    prompt="u@10086 R:m:s [d]> "
    no-auto-rehash
    
    [mysqld]
    user    = karenyin
    port    = 10010
    language = /usr/share/mysql/english
    basedir    = /usr/share/mysql
    datadir    = /home/karenyin/mysql_data/10010/
    socket    = /home/karenyin/mysql_data/10010/mysql.sock
    pid-file = 10086.pid
    character-set-server = utf8mb4
    skip_name_resolve = 1
    open_files_limit    = 65535
    back_log = 1024
    max_connections = 10
    max_connect_errors = 1000000
    table_open_cache = 20
    table_definition_cache = 20
    table_open_cache_instances = 64
    thread_stack = 512K
    external-locking = FALSE
    max_allowed_packet = 32M
    sort_buffer_size = 4M
    join_buffer_size = 4M
    thread_cache_size = 15
    interactive_timeout = 600
    wait_timeout = 600
    tmp_table_size = 32M
    max_heap_table_size = 32M
    slow_query_log = 1
    slow_query_log_file = /home/karenyin/mysql_data/10010/slow.log
    log-error = /home/karenyin/mysql_data/10010/error.log
    long_query_time = 0.1
    log_queries_not_using_indexes =1
    log_throttle_queries_not_using_indexes = 60
    min_examined_row_limit = 100
    log_slow_admin_statements = 1
    log_slow_slave_statements = 1
    server-id = 10010
    log-bin = /home/karenyin/mysql_data/10010/mybinlog
    sync_binlog = 1
    binlog_cache_size = 4M
    max_binlog_cache_size = 200M
    max_binlog_size = 100M
    expire_logs_days = 7
    master_info_repository = TABLE
    relay_log_info_repository = TABLE
    gtid_mode = on
    enforce_gtid_consistency = 1
    log_slave_updates
    slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
    binlog_format = row
    binlog_checksum = 1
    relay_log_recovery = 1
    relay-log-purge = 1
    key_buffer_size = 15M
    read_buffer_size = 8M
    read_rnd_buffer_size = 4M
    bulk_insert_buffer_size = 64M
    myisam_sort_buffer_size = 128M
    myisam_max_sort_file_size = 10G
    myisam_repair_threads = 1
    lock_wait_timeout = 3600
    explicit_defaults_for_timestamp = 1
    innodb_thread_concurrency = 0
    innodb_sync_spin_loops = 100
    innodb_spin_wait_delay = 30
    
    transaction_isolation = REPEATABLE-READ
    #innodb_additional_mem_pool_size = 16M
    innodb_buffer_pool_size = 2007M
    innodb_buffer_pool_instances = 4
    innodb_buffer_pool_load_at_startup = 1
    innodb_buffer_pool_dump_at_shutdown = 1
    innodb_data_file_path = ibdata1:100M:autoextend
    innodb_flush_log_at_trx_commit = 1
    innodb_log_buffer_size = 32M
    innodb_log_file_size = 2G
    innodb_log_files_in_group = 2
    innodb_max_undo_log_size = 4G
    innodb_undo_directory = undolog
    innodb_undo_tablespaces = 95
    
    # 根据您的服务器IOPS能力适当调整
    # 一般配普通SSD盘的话,可以调整到 10000 - 20000
    # 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
    innodb_io_capacity = 4000
    innodb_io_capacity_max = 8000
    innodb_flush_neighbors = 0
    innodb_write_io_threads = 8
    innodb_read_io_threads = 8
    innodb_purge_threads = 4
    innodb_page_cleaners = 4
    innodb_open_files = 65535
    innodb_max_dirty_pages_pct = 50
    innodb_flush_method = O_DIRECT
    innodb_lru_scan_depth = 4000
    innodb_checksum_algorithm = crc32
    innodb_lock_wait_timeout = 10
    innodb_rollback_on_timeout = 1
    innodb_print_all_deadlocks = 1
    innodb_file_per_table = 1
    innodb_online_alter_log_max_size = 4G
    internal_tmp_disk_storage_engine = InnoDB
    innodb_stats_on_metadata = 0
    
    # some var for MySQL 8
    log_error_verbosity = 3
    #innodb_print_ddl_logs = 1
    #binlog_expire_logs_seconds = 604800
    #innodb_dedicated_server = 0
    
    innodb_status_file = 1
    # 注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快
    innodb_status_output = 0
    innodb_status_output_locks = 0
    
    #performance_schema
    performance_schema = 1
    performance_schema_instrument = '%=on'
    
    #innodb monitor
    innodb_monitor_enable="module_innodb"
    innodb_monitor_enable="module_server"
    innodb_monitor_enable="module_dml"
    innodb_monitor_enable="module_ddl"
    innodb_monitor_enable="module_trx"
    innodb_monitor_enable="module_os"
    innodb_monitor_enable="module_purge"
    innodb_monitor_enable="module_log"
    innodb_monitor_enable="module_lock"
    innodb_monitor_enable="module_buffer"
    innodb_monitor_enable="module_index"
    innodb_monitor_enable="module_ibuf_system"
    innodb_monitor_enable="module_buffer_page"
    innodb_monitor_enable="module_adaptive_hash"
    
    [mysqldump]
    quick
    max_allowed_packet = 32M
    View Code



    2. MyCAT安装


    //wget https://raw.githubusercontent.com/MyCATApache/Mycat-download/master/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz


    2.1 修改配置文件

    server.xml  

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mycat:server SYSTEM "server.dtd">
    <mycat:server xmlns:mycat="http://io.mycat/">
        <system>
    
        </system>
    
    
        <user name="karenyin">
            <property name="password">123456</property>
            <property name="schemas">db_music</property>
        </user>
    
    
    </mycat:server>
    View Code

    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="db_music" checkSQLschema="false" sqlMaxLimit="100">
     6         <table name="t_album" primaryKey="id" dataNode="dn_10010,dn_10011,dn_10012" rule="sharding-by-murmur-id">
     7             <childTable name="t_track" joinKey="album" parentKey="id" primaryKey="id"/>
     8         </table>
     9         <table name="t_artist" primaryKey="id" type="global" dataNode="dn_10010,dn_10011,dn_10012" />
    10     </schema>
    11 
    12     <dataNode name="dn_10010" dataHost="droplet_10010" database="db_music" />
    13     <dataNode name="dn_10011" dataHost="droplet_10011" database="db_music" />
    14     <dataNode name="dn_10012" dataHost="droplet_10012" database="db_music" />
    15 
    16     <dataHost name="droplet_10010" maxCon="10" minCon="2" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
    17         <heartbeat>select 1</heartbeat>
    18         <writeHost host="hostM0" url="xxxx:10010" user="karenyin" password="xxxx">
    19         </writeHost>
    20     </dataHost>
    21 
    22     <dataHost name="droplet_10011" maxCon="10" minCon="2" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
    23         <heartbeat>select 1</heartbeat>
    24         <writeHost host="hostM1" url="xxxx:10011" user="karenyin" password="xxxx">
    25         </writeHost>
    26     </dataHost>
    27 
    28     <dataHost name="droplet_10012" maxCon="10" minCon="2" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
    29         <heartbeat>select 1</heartbeat>
    30         <writeHost host="hostM2" url="xxxx:10012" user="karenyin" password="xxxxx">
    31         </writeHost>
    32     </dataHost>
    33 
    34 </mycat:schema>

    rule.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!DOCTYPE mycat:rule SYSTEM "rule.dtd">
     3 <mycat:rule xmlns:mycat="http://io.mycat/">
     4     <tableRule name="sharding-by-murmur-id">
     5         <rule>
     6             <columns>id</columns>
     7             <algorithm>sharding-by-murmur-id</algorithm>
     8         </rule>
     9     </tableRule>
    10     <function name="sharding-by-murmur-id" class="io.mycat.route.function.PartitionByMurmurHash">
    11         <property name="seed">0</property>
    12         <property name="type">0</property>  <!-- 0 for Integer, other for String -->
    13         <property name="count">3</property> <!-- dataNode Count -->
    14         <property name="virtualBucketTimes">128</property> <!-- 最多支持3*128个分片 -->
    15         <property name="bucketMapPath">bucketMapPath-murmur-id</property> <!-- hash分片结果输出 -->
    16     </function>
    17 </mycat:rule>

    2.2 初始化MySQL数据库

    全局表t_artist需要带`_mycat_op_time` bigint(20)字段

    create database db_music;
    use db_music;
    DROP TABLE IF EXISTS t_album(id,name,`release`,artist);
    CREATE TABLE t_album(id,name,`release`,artist) (
      'id' int(10) unsigned zerofill NOT NULL AUTO_INCREMENT,
      'name' varchar(200) NOT NULL,
      `release` date DEFAULT NULL,
      'artist' int(11) DEFAULT NULL,
      PRIMARY KEY ('id')
    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
    DROP TABLE IF EXISTS 't_artist';
    CREATE TABLE 't_artist' (
      'id' int(10) unsigned zerofill NOT NULL AUTO_INCREMENT,
      'artist_name' varchar(200) NOT NULL,
      'birth_date' date NOT NULL,
      '_mycat_op_time' bigint(20) DEFAULT NULL,
      PRIMARY KEY ('id')
    ) ENGINE=InnoDB AUTO_INCREMENT=10004 DEFAULT CHARSET=utf8mb4;
    DROP TABLE IF EXISTS t_track(id,name,seconds,album);
    CREATE TABLE t_track(id,name,seconds,album) (
      'id' int(10) unsigned NOT NULL AUTO_INCREMENT,
      'name' varchar(400) NOT NULL,
      'seconds' int(11) NOT NULL,
      'album' int(11) NOT NULL,
      PRIMARY KEY ('id')
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    
    
    
    INSERT INTO t_artist(id,artist_name,birth_date) VALUES (0000010000, 'Sergei Rachmaninoff', '1873-04-01');
    INSERT INTO t_artist(id,artist_name,birth_date) VALUES (0000010001, 'Franz Schubert', '1797-01-31');
    INSERT INTO t_artist(id,artist_name,birth_date) VALUES (0000010002, 'Eminem', '1972-10-17');
    
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000004, 'Ultimate Schubert', '2007-08-13', 10001);
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000001, 'Schubert: Symphony No 3 in D-Major, D. 200 & "Trout" Piano Quintet in A-Major, D. 667 (History Records - Classical Edition 22 - Original Recordings Digitally Remastered 2011)', '2011-02-05', 10001);
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000002, 'Schubert: Complete Trios', '1993-10-08', 10001);
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000005, 'Schubert: Symphony Nos 8 & 9', '2005-10-24', 10001);
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000003, 'SCHUBERT: String Quartets (Complete), Vol. 1', '2007-09-01', 10001);
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000006, 'Revival', '2017-12-15', 10002);
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000007, 'Kamikaze', '2018-08-31', 10002);
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000008, 'The Marshall Mathers LP 2', '2013-12-02', 10002);
    INSERT INTO t_album(id,name,`release`,artist) VALUES (0000000009, 'Recovery', '2010-6-8', 10002);
     
    
    
    INSERT INTO t_track(id,name,seconds,album) VALUES (1, '''Trout'' Piano Quintet in A Major, D. 667: I. Allegro vivace (1957 Version) 
    ''Trout'' Piano Quintet in A Major, D. 667: I. Allegro vivace (1957 Version) 
    ''Trout'' Piano Quintet in A Major, D. 667: I. Allegro vivace (1957 Version)', 546, 1);
    INSERT INTO t_track(id,name,seconds,album) VALUES (2, '''Trout'' Piano Quintet in A Major, D. 667: II. Andante (1957 Version)', 446, 1);
    INSERT INTO t_track(id,name,seconds,album) VALUES (3, '''Trout'' Piano Quintet in A Major, D. 667: III. Scherzo, Presto (1957 Version)', 247, 1);
    INSERT INTO t_track(id,name,seconds,album) VALUES (4, '''Trout'' Piano Quintet in A Major, D. 667: IV. Andantino - Allegretto (1957 Version)', 452, 1);
    INSERT INTO t_track(id,name,seconds,album) VALUES (5, '''Trout'' Piano Quintet in A Major, D. 667: Allegro giusto (1957 Version)', 415, 1);
    INSERT INTO t_track(id,name,seconds,album) VALUES (11, 'Franz Schubert: String Trio in B flat, D.581 - 1. Allegro moderato', 335, 2);
    INSERT INTO t_track(id,name,seconds,album) VALUES (12, 'Franz Schubert: String Trio in B flat, D.581 - 2. Andante', 303, 2);
    INSERT INTO t_track(id,name,seconds,album) VALUES (13, 'Franz Schubert: String Trio in B flat, D.581 - 3. Menuetto (Allegretto)', 240, 2);
    INSERT INTO t_track(id,name,seconds,album) VALUES (14, 'Franz Schubert: String Trio in B flat, D.581 - 4. Rondo (Allegretto)', 353, 2);
    INSERT INTO t_track(id,name,seconds,album) VALUES (15, 'Franz Schubert: String Trio in B flat, D.471; Allegro - 1. Allegro', 501, 2);
    INSERT INTO t_track(id,name,seconds,album) VALUES (16, 'Franz Schubert: Piano Trio No.1 in B flat, Op.99 D.898 - 1. Allegro moderato', 643, 2);
    
    INSERT INTO t_track(id,name,seconds,album) VALUES (17, 'Walk on Water', 304, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (18, 'Believe', 315, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (19, 'Chloraseptic', 301, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (20, 'Untouchable', 370, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (21, 'River', 221, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (22, 'Remind Me(Intro)', 26, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (23, 'Remind Me', 225, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (24, 'Revival (Interlude)', 51, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (25, 'Like Home', 245, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (26, 'Bad Husband', 287, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (27, 'Tragic Endings', 252, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (28, 'Framed', 253, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (29, 'Nowhere Fast', 264, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (30, 'Heat', 250, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (31, 'Offended', 320, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (32, 'Need Me', 265, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (33, 'In Your Head', 182, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (34, 'Castle', 254, 6);
    INSERT INTO t_track(id,name,seconds,album) VALUES (35, 'Arose', 274, 6);
    
    INSERT INTO t_track(id,name,seconds,album) VALUES (36, 'The Ringer', 337, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (37, 'Greatest', 226, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (38, 'Lucky You', 244, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (39, 'Paul', 35, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (40, 'Normal', 222, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (41, 'Em Calls Paul', 49, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (42, 'Stepping Stone', 309, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (43, 'Not Alike', 288, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (44, 'Kamikaze', 216, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (45, 'Fall', 262, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (46, 'Nice Guy', 150, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (47, 'Good Guy', 142, 7);
    INSERT INTO t_track(id,name,seconds,album) VALUES (48, 'Venom', 269, 7);
    
    
    //|grep -v '^$'|grep -Po '"[w ]+"'|sed 's/"//g'|awk '{print $0 ","}'
    //|grep -v '^$'|grep -Po '[d]+:[d]+'|awk -F ':' '{print $1*60+$2}'
    //|awk -F, '{print "INSERT INTO t_track(id,name,seconds,album) VALUES (" 48+NR ", " $1 ", " $2 ", 8);"}'
    INSERT INTO t_track(id,name,seconds,album) VALUES (49, 'Bad Guy', 434, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (50, 'Parking Lot (skit)', 55, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (51, 'Rhyme or Reason', 301, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (52, 'So Much Better', 261, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (53, 'Survival', 272, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (54, 'Legacy', 296, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (55, 'Asshole', 288, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (56, 'Berzerk', 238, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (57, 'Rap God', 363, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (58, 'Brainless', 286, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (59, 'Stronger Than I Was', 336, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (60, 'The Monster', 250, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (61, 'So Far', 317, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (62, 'Love Game', 296, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (63, 'Headlights', 343, 8);
    INSERT INTO t_track(id,name,seconds,album) VALUES (64, 'Evil Twin', 356, 8);
    
    
    INSERT INTO t_track(id,name,seconds,album) VALUES (65, 'Cold Wind Blows', 303, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (66, 'Talkin 2 Myself (featuring Kobe)', 300, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (67, 'On Fire', 213, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (68, 'Wont Back Down (featuring Pink)', 265, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (69, 'W.T.P.', 238, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (70, 'Going Through Changes', 298, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (71, 'Seduction', 275, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (72, 'No Love (featuring Lil Wayne)', 300, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (73, 'Space Bound', 278, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (74, 'Cinderella Man', 279, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (75, '25 to Life',241, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (76, 'So Bad', 325, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (77, 'Almost Famous', 292, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (78, 'Love the Way You Lie (featuring Rihanna)', 263, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (79, 'Youre Never Over', 305, 9);
    INSERT INTO t_track(id,name,seconds,album) VALUES (80, 'Untitled (hidden track)', 194, 9);
    View Code

    2.3 安装5.6-client

    有win版本navicat的同学可以跳过这一步。

    wget https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.42-1.el6.x86_64.rpm-bundle.tar

    对于mac:brew install mysql@5.6,安装5.6client是因为navicat查询的时候喜欢多发送查询命令,干扰到调试进程。

    3. 验证
    3.1 全局表中插入数据 要求表带_mycat_op_time字段


    insert into t_artist set id='10000', artist_name='Sergei Rachmaninoff', birth_date='1873-04-01';
    insert into t_artist set id='10001', artist_name='Franz Schubert', birth_date='1797-01-31';

    3.2 分库表中插入数据

    use db_music;
    desc t_album;
    ##ERROR 1064 (HY000): partition table, insert must provide ColumnList
    ##insert into t_album values('0','Trout','2012-2-3',10001);

    ##ERROR 1064 (HY000): bad insert sql (sharding column:ID not provided,INSERT INTO t_album (name, release, artist)
    ##insert into t_album(name,release,artist) VALUES('Trout','2012-02-03','10001');

    insert into t_album(id,name) VALUES(0,'Trout');

    ##ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release,artist) VALUES(0,'Trout','2012-02-03','10001')' at line 1

    insert into t_album(id,name,release,artist) VALUES(0,'Trout','2012-02-03','10001');

  • 相关阅读:
    HDOJ 1846 Brave Game
    并查集模板
    HDU 2102 A计划
    POJ 1426 Find The Multiple
    POJ 3278 Catch That Cow
    POJ 1321 棋盘问题
    CF 999 C.Alphabetic Removals
    CF 999 B. Reversing Encryption
    string的基础用法
    51nod 1267 4个数和为0
  • 原文地址:https://www.cnblogs.com/yinkw/p/9969750.html
Copyright © 2011-2022 走看看