1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| 创建表 mysql -S /web/data/mysql/3307/mysql.sock -e "use test;CREATE TABLE user (id BIGINT PRIMARY KEY,name VARCHAR(50),age_id BIGINT);" mysql -S /web/data/mysql/3307/mysql.sock -e "use test;CREATE TABLE age (age_id BIGINT PRIMARY KEY,age_value INT);" mysql -S /web/data/mysql/3308/mysql.sock -e "use test;CREATE TABLE user (id BIGINT PRIMARY KEY,name VARCHAR(50),age_id BIGINT);" mysql -S /web/data/mysql/3308/mysql.sock -e "use test;CREATE TABLE age (age_id BIGINT PRIMARY KEY,age_value INT);"
重启mycat mycat restart
插入数据 mysql -uroot -p123456 -h192.168.177.200 -P8066 use TESTDB INSERT INTO user (id, name, age_id) VALUES (2, 'A', 20); INSERT INTO user (id, name, age_id) VALUES (4, 'B', 40); INSERT INTO user (id, name, age_id) VALUES (6, 'C', 60); INSERT INTO age (age_id, age_value) VALUES (20, 20); INSERT INTO age (age_id, age_value) VALUES (40, 40); INSERT INTO age (age_id, age_value) VALUES (60, 60);
验证 SELECT user.age_id, user.id, user.name, age.age_value FROM user LEFT JOIN age ON user.age_id = age.age_id; +--------+----+------+-----------+ | age_id | id | name | age_value | +--------+----+------+-----------+ | 20 | 2 | B | 30 | | 10 | 1 | A | 25 | | 30 | 3 | C | 35 | +--------+----+------+-----------+
|