zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Mycat 运行与基础操作4

2023-04-18 14:27:33 时间

连接服务

连接方法和mysql一样,里面呈现出的CLI界面也与mysql非常相似

[root@h101 ~]# mysql -u cc -p -P 8066 -h 192.168.100.102
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.5.8-mycat-1.5-GA-20160217103036 MyCat Server (OpenCloundDB)

Copyright (c) 2000, 2015, 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> show databases;
+----------+
| DATABASE |
+----------+
| cctest   |
+----------+
1 row in set (0.01 sec)

mysql> use cctest;
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 cctest |
+------------------+
| catworld         |
| catworld4        |
+------------------+
2 rows in set (0.00 sec)

mysql> 

创建表

我虽然在mycat里定义了,但在真实库中并没有创建过这两张表

mysql> show tables;
+------------------+
| Tables in cctest |
+------------------+
| catworld         |
| catworld4        |
+------------------+
2 rows in set (0.00 sec)

mysql> desc catworld4;
ERROR 1146 (42S02): Table 'my3.catworld4' doesn't exist
mysql> 

Tip: 此时在后端真实库里,是找不到这两张表的

这张表是要我们手动创建的,可以有两种方式

  • 在每个数据节点里手动创建出一样的数据表
  • 直接在mycat里创建,mycat会再分别去各数据节点创建

这里,我使用第二种方式,直接在mycat里创建

mysql> create table catworld4(id int primary key, name varchar(30));
Query OK, 0 rows affected (0.69 sec)

mysql> desc catworld4;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(30) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.05 sec)

mysql> explain desc catworld4;
+-----------+----------------+
| DATA_NODE | SQL            |
+-----------+----------------+
| sd1       | desc catworld4 |
+-----------+----------------+
1 row in set (0.04 sec)

mysql>