在 MySql Connector/Net 上设置 PAD_CHAR_TO_FULL_LENGTH

Set PAD_CHAR_TO_FULL_LENGTH on MySql Connector/Net

MySQL Reference Manual所述,

The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255. When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed unless the PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled.

如何在 Connector/Net 中启用 PAD_CHAR_TO_FULL_LENGTH 标志? (不是 ODBC)

Server SQL Modes 中所述:

To change the SQL mode at runtime, set the global or session sql_mode system variable using a SET statement:

SET GLOBAL sql_mode = '<strong><em>modes</em></strong>';
SET SESSION sql_mode = '<strong><em>modes</em></strong>';

Setting the GLOBAL variable requires the SUPER privilege and affects the operation of all clients that connect from that time on. Setting the SESSION variable affects only the current client. Each client can change its session sql_mode value at any time.

因此,您想按照以下几行执行普通的旧 SQL 命令:

SET SESSION sql_mode = 'PAD_CHAR_TO_FULL_LENGTH';