I ran
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
and the output is
+--------------------------+-------------------+
| Variable_name | Value |
+--------------------------+-------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+--------------------------+-------------------+
Can someone please explain the exact usage of these settings? My understanding is following:
- character_set_client: Tells the encoding used by client for query encoding
- character_set_connection: Encoding used by server to convert query into
- character_set_database: encoding used for storing data in tables
- character_set_server: Default encoding if character_set_connection not specified
- character_set_results: Results are encoded in this format and returned.
Why are there are so many configs required? Couldn't client and server config be kept same always?
I am trying to perform an insert query which fails due to presence of ' in string. Is it recommended to escape it or encode the query? Also, how can I encode it in golang?