• MySQL乱码问题及字符集实战


    mysql> create database oldboy;
    Query OK, 1 row affected (0.01 sec)

    mysql>
    mysql>
    mysql> show create database oldboyG;
    *************************** 1. row ***************************
    Database: oldboy
    Create Database: CREATE DATABASE `oldboy` /*!40100 DEFAULT CHARACTER SET utf8 */
    1 row in set (0.00 sec)

    ERROR:
    No query specified

    mysql> create table students (id int(4) not null auto_increment,name char(20) not null,primary key (`id`));
    Query OK, 0 rows affected (0.06 sec)


    mysql> select * from students;
    +----+-------+
    | id | name |
    +----+-------+
    | 1 | alex |
    | 2 | simon |
    | 3 | ys |
    | 5 | ?? |
    | 6 | ??? |
    +----+-------+
    5 rows in set (0.00 sec)

    mysql> set names utf8;
    Query OK, 0 rows affected (0.00 sec)

    mysql> select * from students;
    +----+-----------+
    | id | name |
    +----+-----------+
    | 1 | alex |
    | 2 | simon |
    | 3 | ys |
    | 5 | 永三 |
    | 6 | 李永三 |
    +----+-----------+
    5 rows in set (0.00 sec)


    mysql> select * from students;
    +----+-------+
    | id | name |
    +----+-------+
    | 1 | alex |
    | 2 | simon |
    | 3 | ys |
    | 5 | ?? |
    | 6 | ??? |
    +----+-------+
    5 rows in set (0.00 sec)

    mysql> insert into students values(7,'李永三');
    Query OK, 1 row affected (0.05 sec)

    mysql> select * from students;
    +----+-----------+
    | id | name |
    +----+-----------+
    | 1 | alex |
    | 2 | simon |
    | 3 | ys |
    | 5 | ?? |
    | 6 | ??? |
    | 7 | 李永三 |
    +----+-----------+
    6 rows in set (0.00 sec)

    mysql> show create database oldboy;
    +----------+-----------------------------------------------------------------+
    | Database | Create Database |
    +----------+-----------------------------------------------------------------+
    | oldboy | CREATE DATABASE `oldboy` /*!40100 DEFAULT CHARACTER SET utf8 */ |
    +----------+-----------------------------------------------------------------+
    1 row in set (0.00 sec)

    mysql> show create table studentsG;
    *************************** 1. row ***************************
    Table: students
    Create Table: CREATE TABLE `students` (
    `id` int(4) NOT NULL AUTO_INCREMENT,
    `name` char(20) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8
    1 row in set (0.00 sec)


    不乱码的思想:建议中英文混合的环境选择utf8

    Linux:
    [yongsan@yz3110 mysqldump]$ cat /etc/sysconfig/i18n
    LANG="en_US.UTF-8"
    SYSFONT="latarcyrheb-sun16"


    客户端
    临时:
    mysql> set names utf8;
    或更改mysql.cnf的配置参数,永久生效:
    [yongsan@yz3110 ~]$ cat /usr/local/mysql55/start/my.cnf |grep set
    character-set-server = utf8
    character_set_client = utf8

    服务器
    更改mysql.cnf的参数
    [mysqld]
    character-set-server = utf8
    character_set_client = utf8

    库、表、程序字符集
    mysql> create database ys default character set utf8;
    Query OK, 1 row affected (0.03 sec)

  • 相关阅读:
    170516、ActiveMQ 的安装与使用(单节点)
    170515、mybatis批量操作
    170512、java日志文件log4j.properties配置详解
    170511、Spring IOC和AOP 原理彻底搞懂
    170510、数据库默认隔离级别
    170509、文本编辑器编写的shell脚本在linux下无法执行的解决方法
    170508、忘记jenkins密码或者修改jenkins密码
    170505、MySQL的or/in/union与索引优化
    170504、MongoDB和MySQL对比(译)
    Jenkins Android 打包
  • 原文地址:https://www.cnblogs.com/liyongsan/p/5320536.html
Copyright © 2020-2023  润新知