Error
Error Code:
1628
MySQL Error 1628: Table Comment Too Long
Description
MySQL Error 1628 occurs when the descriptive comment provided for a table exceeds the maximum character length allowed by the database system. This typically happens during `CREATE TABLE` or `ALTER TABLE` operations when the `COMMENT` clause is too verbose.
Error Message
Comment for table '%s' is too long (max = %lu)
Known Causes
3 known causesExceeded Maximum Comment Length
The `COMMENT` clause specified in the SQL statement for creating or altering a table contains more characters than the maximum allowed length for table comments in MySQL.
Overly Descriptive Table Comment
Attempting to embed extensive documentation, detailed notes, or very long descriptions directly within the table's comment field, which is designed for brief metadata.
MySQL Version/Engine Limit Differences
While less common, specific MySQL versions or storage engines (e.g., InnoDB, MyISAM) might have slightly different maximum comment lengths, causing an error if a comment valid elsewhere is too long here.
Solutions
3 solutions available1. Truncate Existing Table Comment easy
Shorten the comment of the table causing the error.
1
Identify the table name causing the error. The error message '%s' will contain the table name.
2
Connect to your MySQL server using a client like the MySQL command-line client or MySQL Workbench.
mysql -u your_user -p
3
Execute the ALTER TABLE statement to modify the table's comment, ensuring it's within the allowed length. The maximum length is usually 60 characters for older MySQL versions or can be larger for newer ones. You can find the exact limit by querying `SHOW VARIABLES LIKE 'max_long_data_length';` or `SHOW VARIABLES LIKE 'innodb_page_size';` and considering its relationship to the comment length. For simplicity, aim for under 60 characters.
ALTER TABLE your_table_name COMMENT = 'Your shortened comment here';
4
Verify the change by describing the table.
DESCRIBE your_table_name;
2. Remove Table Comment Entirely easy
Completely remove the comment from the table if it's not essential.
1
Identify the table name from the error message.
2
Connect to your MySQL server.
mysql -u your_user -p
3
Execute the ALTER TABLE statement to remove the comment.
ALTER TABLE your_table_name COMMENT = '';
4
Confirm the comment is removed.
DESCRIBE your_table_name;
3. Increase Max Comment Length (Advanced) advanced
Modify MySQL server configuration to allow longer table comments.
1
Locate your MySQL configuration file (my.cnf or my.ini). The location varies by OS and installation method.
2
Edit the configuration file. Add or modify the `max_long_data_length` variable within the `[mysqld]` section. The default is often 65535 bytes, but comments might have a practical limit imposed by other factors or older versions. Be aware that increasing this significantly might have performance implications or be limited by underlying storage engine capabilities.
[mysqld]
max_long_data_length = 1048576 # Example: 1MB, adjust as needed
3
Save the configuration file.
4
Restart the MySQL server for the changes to take effect.
sudo systemctl restart mysql # For systemd-based systems
# Or use the appropriate command for your OS.
5
After restarting, you can retry creating or altering the table with a longer comment. You can verify the setting with `SHOW VARIABLES LIKE 'max_long_data_length';`.
SHOW VARIABLES LIKE 'max_long_data_length';