The mysql command prompts for the resolution of the connection mess

  • 2020-05-10 23:01:34
  • OfStack

WINDOWS
1. MySQL has some environment variables that can be set.
Available for input: show variables; View the current environment variable Settings;
2. Among these variables, 1 part has character-related Settings,
Available for input: show variables like ´ character % & acute;; To view;
3. Where character_set_results determines the encoding of the return result,
windows is set to gb2312 to display Chinese normally;
Setting method: set character_set_results=gb2312; , and then press enter;
4. Of course, if you want to modify the database contents in Chinese through the command prompt window,
Try set character_set_connection=gb2312;
And set character_set_client = gb2312;
Description:
The above values are set in the command prompt window,
The validity period is only valid for this connection,
That is, after disconnecting this connection,
Reconnect,
All set variables are back to their default values.
ubuntu 9.0.4 mysql messy code solution
Operating system environment:
ubuntu9.0.4, MySql5.1 (installed via sudo apt-get install mysql5.1)
Phenomenon:
In the end
1. mysql-uroot-proot enters mysql client
2.use parking selects 1 database
3.select *from users select 1 user table
Inside the Chinese field is displayed as??
4. Use statement show variables like 'character%'
There are several options for latin, not utf8
Solution steps:
1. Find the configuration file for mysql
mysql configuration file is/etc/init d/mysql/my cnf. (if not ubuntu9. 0.4, this file is not 1 set exist, because you might take MySQL installation with online said no 1 sample, was not one to 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 doesn't have to exist, you should go to *.cnf.
Should be backup cp under 1/2. Modify etc/init d/mysql/my cnf/etc/my cnf. bak
Open my.cnf to 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
Depending on how you install mysql, restart your mysql with different commands. If you have configured to use mysqld self-boot mode, you can do it
cd /usr/bin/
mysqladmin-uroot-proot shutdownmysqld_safe & (sudo mysql_safe & if you don't have enough permissions)
4. Use statement show variables like 'character%'
Only one would be latin and the rest would be utf8

Change the cmd(dos) encoding under windows to UTF-8
chcp command,
chcp 65001 is simply replaced by the UTF-8 code page
chcp 936 can be swapped back to the default GBK
chcp 437 is an American English note: personal testing of CMD under the modification of the code can not solve the MYSQL scrambled code

Related articles: