Django 2 MySQL and Blog
mysql usage
In this post I am going writting some useful commonds of mysql, hand this you can operate Database as cake. 1. Change specific database encode
ALTER DATABASE ara CHARACTER SET utf8;
- Change all database encode ``` SET CHARACTER_SET_CONNECTTION=utf8; SET CHARACTER_SET_DATABASE=utf8; SET CHARACTER_SET_SERVER=utf8; SET CHARACTER_SET_CLIENT=utf8;
3. **Ultimate method to change encode of mysql**
ok, I have to admmit that above method you cannot really change mysql's encode, it still be latin1 for character_database and character_server. But using this you can change the encode method forever. First of all, please make sure you have stop mysql.
**Step 1**
copy `my-default.cnf` to `/etc/my.cnf`, using:
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
**Step 2**
changing a exactly right to that file, make sure only you can write and read it, using:
sudo chmod 644 my.cnf
**Step 3**
add this lines to the file:
sudo vim my.cnf
[client] default-character-set=utf8
under `[mysqld]` adding this:
default-storage-engine=INNODB character-set-server=utf8 collation-server=utf8_general_ci
ok, then save and quit, start mysql, and you will find:
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/local/mysql-5.7.16-osx10.11-x86_64/share/charsets/ | +————————–+———————————————————+ 8 rows in set (0.01 sec) ```