MySQL Workbench 和 SEQUEL Pro 按字母顺序创建主键

MySQL Workbench and SEQUEL Pro create primary key alphabetically

我通过两个程序连接到我的数据库:MySql Workbench 和 Sequel Pro(它是托管在 heroku 上的 ClearDB MySQL 数据库)。我创建了一个简单的 table:

CREATE TABLE Country( 
    CountryID int AUTO_INCREMENT NOT NULL, 
    Name varchar(50), 
    PRIMARY KEY(CountryID)
);

然后我添加了一些条目:

INSERT INTO Country(Name) VALUES ("Poland");
INSERT INTO Country(Name) VALUES ("Germany");
INSERT INTO Country(Name) VALUES ("Sweden");
INSERT INTO Country(Name) VALUES ("France");

问题是当我执行 SELECT * FROM city 时,我得到如下结果,其中 PRIMARY KEY 按 alphabetical/lexicographical 顺序自动递增:

1, Poland
21, Germany
31, Sweden
41, France

我希望 PRIMARY KEY 为 1、2、3、4 等

我找不到任何设置,也找不到任何可以说明为什么会发生这种情况的帖子。有人有线索吗?

我不明白你的意思:

the problem is when I search for the contents in this table they are being created with PRIMARY KEY in alphabetical/lexicographical order

但是根据您的示例数据,键是按照输入数据的顺序分配的,这正是人们所期望的。至于为什么键值之间有十个跳跃,这是ClearDB的故意:

When I use auto_increment keys (or sequences) in my database, they increment by 10 with varying offsets. Why?

ClearDB uses circular replication to provide master-master MySQL support. As such, certain things such as auto_increment keys (or sequences) must be configured in order for one master not to use the same key as the other, in all cases. We do this by configuring MySQL to skip certain keys, and by enforcing MySQL to use a specific offset for each key used. The reason why we use a value of 10 instead of 2 is for future development.