zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    13.解决SUSELinux用户登录Module is unknow问题
    12.解决SUSE Linux无法使用SSH登录的问题
    11.SUSE Linux服务器系统网卡配置重启问题
    02.Windows2012R2安装360安全卫士失败及无法卸载问题
    01.Windows2008R2系统禁启SMBv1服务命令
    07.SUSE Linux 系统本地yum源配置
    06.Linux-RedHat系统本地yum源配置
    05.Linux-CentOS系统本地Yum源搭建
    04.Linux-CentOS系统sudo权限配置
    03.LinuxCentOS系统root目录LVM磁盘扩容
  • 原文地址:https://www.cnblogs.com/liyongsan/p/5320536.html
Copyright © 2011-2022 走看看