Solution to Linux database garbled code

Release: 2019-12-25 13:58:18
Original
2241 people have browsed it

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/
Copy after login

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

/usr/share/mysql
Copy after login

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

/usr/bin
Copy after login

4. Startup script (such as mysql startup command)

/etc/rc.d/init.d/
Copy after login

View default Character set

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

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!