As MySQL Reference Manual states,
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.
How to enable PAD_CHAR_TO_FULL_LENGTH flag in Connector/Net? (not ODBC)
As documented under Server SQL Modes:
To change the SQL mode at runtime, set the global or session
sql_mode
system variable using aSET
statement:SET GLOBAL sql_mode = 'modes'; SET SESSION sql_mode = 'modes';
Setting the
GLOBAL
variable requires theSUPER
privilege and affects the operation of all clients that connect from that time on. Setting theSESSION
variable affects only the current client. Each client can change its sessionsql_mode
value at any time.
Therefore you want to execute a plain old SQL command along the following lines:
SET SESSION sql_mode = 'PAD_CHAR_TO_FULL_LENGTH';