Mycat水平分表,垂直分表实践(2)(二)

2015-11-21 01:31:33 · 作者: · 浏览: 9
UPDATE MYCAT_SEQUENCE SET current_value = current_value + increment WHERE name = seq_name; RETURN mycat_seq_currval(seq_name); END ;; DELIMITER ; DROP FUNCTION IF EXISTS `mycat_seq_setval`; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `mycat_seq_setval`(seq_name VARCHAR(50), value INTEGER) RETURNS varchar(64) CHARSET latin1 DETERMINISTIC BEGIN UPDATE MYCAT_SEQUENCE SET current_value = value WHERE name = seq_name; RETURN mycat_seq_currval(seq_name); END ;; DELIMITER ; --同时增加权限,否则不能执行。 mysql> grant all privileges on *.* to root@"%" identified by "."; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

4,测试mycat数据库

?mycat数据库的ip是192.168.1.16,端口是8066。
mysql -umycat -pmycat -P8066 -h 192.168.1.16


mysql> show databases;
+---------------+
| DATABASE      |
+---------------+
| blog_article  |
| blog_category |
| blog_user     |
| mycat         |
+---------------+
4 rows in set (0.00 sec)

mysql> use blog_user;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------+
| Tables in blog_user |
+---------------------+
| user_info           |
+---------------------+
1 row in set (0.00 sec)

mysql> insert into user_info(email,`name`,password,create_time,update_time,last_login_time) values('zhangsan@126.com','zhangsan',password('123456'),now(),now(),now());
Query OK, 1 row affected (0.01 sec)

mysql>
select * from user_info; +----+------------------+----------+-------------------------------------------+---------------------+---------------------+---------------------+ | id | email | name | password | create_time | update_time | last_login_time | +----+------------------+----------+-------------------------------------------+---------------------+---------------------+---------------------+ | 1 | zhangsan@126.com | zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 2015-03-26 02:47:38 | 2015-03-26 02:47:38 | 2015-03-26 02:47:38 | +----+------------------+----------+-------------------------------------------+---------------------+---------------------+---------------------+ 1 row in set (0.11 sec) mysql> update user_info set name = 'lisi' where id = 1; Query OK, 1 row affected (0.08 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> delete from user_info where name = 'lisi'; Query OK, 1 row affected (0.00 sec) mysql> use blog_category; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +-------------------------+ | Tables in blog_category | +-------------------------+ | category | | link | | tag | +-------------------------+ 3 rows in set (0.00 sec) mysql> insert into tag(id,user_id,name) values(1,1,'java'); Query OK, 1 row affected (0.11 sec) mysql> select * from tag; +----+---------+------+ | id | user_id | name | +----+---------+------+ | 1 | 1 | java | +----+---------+------+ 1 row in set (0.11 sec) mysql> update tag set name = 'j2ee' where id = 1; Query OK, 1 row affected (0.08 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> insert into tag(user_id,name) values(2,'mysql'); Query OK, 1 row affected (0.00 sec) mysql> select * from tag; +----+---------+-------+ | id | user_id | name | +---