Method 1:
Log in to MySQL, first do set names latin1, and then update the statement or execute the SQL statement
mysql> set names latin1; mysql> source test.sql;
Method 2:
Specify set names latin1 in the SQL file; then log in to MySQL and execute the corresponding file
[root@localhost ~]# cat test.sql set names latin1; insert *****************; mysql> source test.sql;
Method three:
Specify set names latin1 in the SQL file; then import through the MySQL command
[root@localhost ~]# mysql -uroot -p123456 test <test.sql
Method 4:
Achieved by specifying the character set parameter of the MySQL command--default-character-set=latin1
[root@localhost ~]# cat test.sql insert *****************; [root@localhost ~]# mysql -uroot -p123456 --default-character-set=latin1 test <test.sql
Method 5: This method is recommended, but it is recommended to use utf8
Set client and server related parameters in the configuration file
That is, modifying the module parameters of the my.cnf client can implement set names utf8 and take effect permanently
[client] default-character-set=utf8 无需重启MySQL,退出当前登录,重新登录即可 [server] default-character-set=utf8 5.1以前的版本 character-set-server=utf8 5.5版本
Library tables, programs!
The code is as follows:
CREATE DATABASE wyb DEFAULT CHARACTER SET utf8 collate utf8_general_cli;
mysql> show variables like 'character_set%'; | character_set_client | utf8 #客户端字符集 | character_set_connection | utf8 #链接字符集 | character_set_database | utf8 #数据库字符集,配置文件指定或者创建时指定 | character_set_results | utf8 #返回结果字符集 | character_set_server | utf8 #服务器字符集,配置文件,或者创建库,表时候指定
This article is from the “crazy_sir” blog