ubuntu Mysql garbled solution: 1. Find the client and add "default-character-set=utf8"; 2. Find mysqld_safe and add "default-character-set=utf8"; 3. Restart mysql.
The operating environment of this article: ubuntu 16.04 system, mysql version 5.5, Dell G3 computer.
How to solve the ubuntu mysql garbled problem?
Solution to Chinese garbled characters in MySQL in Ubuntu:
1. Log in as root and enter the command sudo gedit /etc/mysql/my.cnf in the terminal to open it In the file
find [client] and add it below
default-character-set=utf8
Find [mysqld_safe] and add it below
default-character-set=utf8
Find [mysqld] and add it below, after 12.04
character-set-server=utf8 init_connect='SET NAMES utf8'
or before 12.04
default-character-set=utf8 init_connect='SET NAMES utf8'
Find [mysql] and add
default-character-set=utf8
2. Restart the mysql command to make your above modifications take effect
Disable the command: sudo mysqladmin shutdown -u root -p
Enable command: sudo /etc/init.d/mysql restart
or: sudo mysqld_safe -user=mysql &
3. Check the current mysql encoding
Enter the mysql command: sudo mysql -u root -p
Check the mysql character set command: show variables like 'character%';
+--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+
4 .The originally built libraries and tables cannot take effect and are still garbled, but the newly created ones can display Chinese normally!
Recommended learning: "mysql video tutorial"
The above is the detailed content of How to solve ubuntu mysql garbled problem. For more information, please follow other related articles on the PHP Chinese website!