The primary key length limit for TDSQL MySQL is 767 bytes. This limitation arises because InnoDB, the storage engine used by MySQL, reserves 3 bytes for the primary key's internal row identifier, leaving 767 bytes for the actual key data.
For instance, if you use a UTF-8 character set, each character can take up to 3 bytes. Therefore, the maximum length of a primary key composed of characters would be approximately 255 characters (767 bytes / 3 bytes per character).
In scenarios where a longer primary key is required, you might consider using a composite primary key, which combines multiple columns to form the key. This approach allows you to work within the byte limit while still uniquely identifying records.
If you're working in a cloud environment and need a managed database service, Tencent Cloud's TDSQL MySQL offers robust support for primary keys and other database features, ensuring high performance and reliability.