How to create a utf8 db with mysqladmin
I feel like this should be simple but i can't work out how to set the character set when making a db with "mysqladmin create". I thought this would work
mysqladmin -u root db_name --characte开发者_如何转开发r-set=utf8
leveraging this bit of the mysqladmin --help text:
-O, --set-variable=name Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.
i also tried this
mysqladmin -u root create db_name --default-character-set=utf8
In both cases, the db was created without complaint, but i don't think it's worked:
mysql> SHOW VARIABLES like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
I can see that character_set_system is utf8, but should all of the latin1's above be showing utf8?
Grateful for any advice - max
No, the variables that you have displayed are the options of your connection, not the database. If you make a database dump, you will see, that everything is in place. For more options see SET NAMES 'charset' command in MySQL Manual.
I'm coming back to answer my own question, since i just tried to do this with a more recent install of mysql and it didn't work: i think the options have changed.
In mysql 5.5, which i have, the relevant config options (to make databases default to utf8 character set) are:
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8
精彩评论