Mysql Command Prompt line connection garbled Solution

Source: Internet
Author: User
When I connected to the mysql database under dos today, garbled characters appeared. For more information, see.

When I connected to the mysql database under dos today, garbled characters appeared. For more information, see.

WINDOWS
1. MySQL has some environment variables that can be set,
You can enter show variables to view the current environment variable settings;
2. Some of these variables have character-related settings,
You can enter: show variables like 'character % '; view;
3. character_set_results determines the encoding of the returned result,
If windows is set to gb2312, Chinese characters can be displayed normally;
Set character_set_results = gb2312; and press Enter;
4. Of course, if you want to enter Chinese characters to modify the database content in the command prompt line window,
Set character_set_connection = gb2312;
And set character_set_client = gb2312;
Note:
The above values are set in the command prompt line window,
The validity period is only valid for this connection,
That is, after the connection is closed,
Reconnect in,
All the set variables are restored to the default values.
Ubuntu9.0.4 mysql garbled Solution
Operating system environment:
Ubuntu9.0.4 and MySql5.1 (via sudo apt-get install mysql5.1)
Symptom:
On the terminal
1. mysql-uroot-proot enter the mysql client
2. use parking to select a database
3. select * from users select a user table
The Chinese field is displayed ???
4. Use the statement show variables like 'character %'
It will display several options that are latin, not utf8
Solution:
1. Find the mysql configuration file
The mysql configuration file is/etc/init. d/mysql/my. cnf. (This file does not necessarily exist if it is not ubuntu9.0.4. Since the MySQL installation method you may use is different from the one mentioned on the Internet, you may not be able to find/etc/init. d/mysql/my. cnf. Therefore, you need to use the find command to find the cnf file. Remember not to go to my. cnf because it does not necessarily exist, but should look for *. cnf.
2. Back up cp/etc/init. d/mysql/my. cnf/etc/my. cnf. bak before modification.
Open my. cnf and modify the encoding.
# Sudo vi/etc/init. d/mysql/my. cnf
Add under [mysqld]
Default-character-set = utf8
Add under [client]
Default-character-set = utf8
3. Restart mysql
Use unused commands to restart your mysql instance based on the method in which you install mysql. If you have configured the mysqld auto-start mode, you can execute
Cd/usr/bin/
Mysqladmin-uroot-proot shutdownmysqld_safe & (if the permission is insufficient, run sudo mysql_safe &)
4. Use the statement show variables like 'character %'
Only one is latin and the other is utf8.

Change the cmd (dos) encoding method in windows to UTF-8
Chcp command,
Chcp 65001 is replaced with the UTF-8 code page
Chcp 936 can be switched back to the default GBK
Chcp 437 is in the United States. Note: modifying the encoding in personal testing CMD cannot solve MYSQL garbled characters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.