How to insert latin characters into Mysql from the command line shell?
Why can't I insert the word Español via the command line mysql program ? S开发者_如何学Cee session below.
mysql> select CONCAT( 'Espa', 0xF1, 'ol' );
+------------------------------+
| CONCAT( 'Espa', 0xF1, 'ol' ) |
+------------------------------+
| Español |
+------------------------------+
1 row in set (0.00 sec)
mysql> create table t
> (
> nom varchar(25) NOT NULL
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql> insert into t VALUES( CONCAT( 'Espa', 0xF1, 'ol' ) );
Query OK, 1 row affected, 1 warning (0.02 sec)
mysql> select * from t;
+------+
| nom |
+------+
| Espa |
+------+
1 row in set (0.00 sec)
mysql> select HEX(nom) from t;
+----------+
| HEX(nom) |
+----------+
| 45737061 |
+----------+
mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
0xf1
is not a valid UTF-8 sequence, so it chokes on that. Use the proper UTF-8 sequence instead:
$ python -c "print repr('\xf1'.decode('latin-1').encode('utf-8'))"
'\xc3\xb1'
It seems to work with latin1 as the default charset.
精彩评论