Home  >  Article  >  Operation and Maintenance  >  Solution to Linux database garbled code

Solution to Linux database garbled code

尚
Original
2019-12-25 13:58:182273browse

Solution to Linux database garbled code

The default character set of MySQL after installation is latin1. In order to change its character set to what the user needs (such as utf8), you must change its related configuration files; because The default installation directory of MySQL under Linux is distributed in different files; it is not placed in the same directory like Windows. You only need to modify the my.ini file and it will take effect after restarting; so let’s take a look at the MySQL under Linux first. Database files, configuration files and command files are in different directories:

1. Database directory, and the database files created are all in this directory

/var/lib/mysql/

2. Configuration file (mysql. server command and configuration file location)

/usr/share/mysql

3. Related commands (such as mysql mysqladmin, etc.)

/usr/bin

4. Startup script (such as mysql startup command)

/etc/rc.d/init.d/

View default Character set

#mysql -u root - p 
#(输入密码) 
mysql> show variables like 'character_set%';

Solution to Linux database garbled code

Modify the character set and modify the /etc/my.cnf file

#/etc/my.cnf
 
[client]
default-character-set=utf8
 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#default-character-set=utf8
character-set-server=utf8
init_connect='SET NAMES utf8'
 
[mysql]
no-auto-rehash
default-character-set=utf8
 
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Remember: What is added to mysqld is character-set-server= utf8 instead of default-character-set=utf8.

Recommended related articles and tutorials: linux tutorial

The above is the detailed content of Solution to Linux database garbled code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn