Home Operation and Maintenance Linux Operation and Maintenance Reasons and solutions for Chinese garbled characters (Chinese question marks) in mysql under Linux

Reasons and solutions for Chinese garbled characters (Chinese question marks) in mysql under Linux

Nov 14, 2019 pm 01:52 PM
linux mysql Chinese garbled reason Solution

Reasons and solutions for Chinese garbled characters (Chinese question marks) in mysql under Linux

The default character set of installed MySQL is latin1. In order to change its character set to what the user needs (such as utf8), its related configuration files must be changed.

Since 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 first let’s take a look at the database files, configuration files and command files of MySQL under Linux in different directories:

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

/var/lib/mysql/
Copy after login

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

/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

Solution:

1. View the default character set

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

Reasons and solutions for Chinese garbled characters (Chinese question marks) in mysql under Linux

2. Change the character set by modifying 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 : added in mysqld It's character-set-server=utf8 instead of default-character-set=utf8. Otherwise, it will report: Starting MySQL...The server quit without updating PID file [Failure]lib/mysql/localhost.localdomain.pid).Exception

3. Restart MySQL server to make its settings effective

一、启动方式
1、使用 service 启动:service mysqld start
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start
3、使用 safe_mysqld 启动:safe_mysqld&
 
二、停止
1、使用 service 启动:service mysqld stop
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld stop
3、 mysqladmin shutdown 
 
三、重启
1、 使用 service 启动:service mysqld restart
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart
Copy after login

Reasons and solutions for Chinese garbled characters (Chinese question marks) in mysql under Linux

Recommended tutorial: Linux tutorial

The above is the detailed content of Reasons and solutions for Chinese garbled characters (Chinese question marks) in mysql under Linux. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

How to solve the problem of printing spaces in IDEA console logs? How to solve the problem of printing spaces in IDEA console logs? Apr 19, 2025 pm 09:57 PM

How to solve the problem of printing spaces in IDEA console logs? When using IDEA for development, many developers may encounter a problem: the console printed...

How to parse next-auth generated JWT token in Java and get information in it? How to parse next-auth generated JWT token in Java and get information in it? Apr 19, 2025 pm 08:21 PM

In processing next-auth generated JWT...

See all articles