你好,游客 登录 注册 搜索
背景:
阅读新闻

虚拟机Ubuntu 9.04下MySQL集群的配置方法

[日期:2009-07-16] 来源:Ubuntu社区  作者:suitq [字体:大 中 小]

执行这类操作时应记住三点

1.

表必须用ENGINE=NDB或ENGINE=NDBCLUSTER选项创建,或用ALTER TABLE选项更改,以使用NDB Cluster存储引擎在 Cluster内复制它们。如果使用mysqldump的输出从已有数据库导

入表,可在文本编辑器中打开SQL脚本,并将该选项添加到任何表创建语句,或用这类选项之一替换任何已有的ENGINE(或TYPE)选项。
2.

另外还请记住,每个NDB表必须有一个主键。如果在创建表时用户未定义主键,NDB Cluster存储引擎将自动生成隐含的主键。(注释:该隐含 键也将占用空间,就像任何其他的表

索引一样。由于没有足够的内存来容纳这些自动创建的键,出现问题并不罕见)。
3.

当你在一个节点上运行create database mydb;你去其他sql node上执行show databases;将不能看到mydb,你需要创建它,然后use mydb; show tables;你将看到同步的表。

SQL Node 1

neo@sql:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7
Server version: 5.0.51a-3Ubuntu5.1 (Ubuntu)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql> create database cluster;
Query OK, 1 row affected (0.00 sec)

mysql> use cluster
Database changed
mysql> create table city( id mediumint unsigned not null auto_increment primary key, name varchar(20) not null default ” ) engine = ndbcluster default

charset utf8;
Query OK, 0 rows affected (1.07 sec)

mysql> insert into city values(1, ‘Shenzhen’);
Query OK, 1 row affected (0.12 sec)

mysql> insert into city values(2, ‘Guangdong’);
Query OK, 1 row affected (0.00 sec)

SQL Node 2

neo@sql:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7
Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| example |
| mydb |
| mysql |
| neo |
+——————–+
6 rows in set (0.13 sec)

mysql> create database cluster;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| cluster |
| example |
| mydb |
| mysql |
| neo |
+——————–+
6 rows in set (0.13 sec)

mysql> use cluster;
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_cluster |
+——————-+
| city |
+——————-+
1 row in set (0.01 sec)

mysql> select * from city;
+—-+———–+
| id | name |
+—-+———–+
| 1 | Shenzhen |
| 2 | Guangdong |
+—-+———–+
2 rows in set (0.03 sec)

mysql>

linux
相关资讯       Ubuntu 9.04 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款