• 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)

  • 相关阅读:
    C++入门经典-例5.19-指针的引用与传递参数
    C++入门经典-例5.18-通过引用交换数值
    C++入门经典-例5.17-右值引用的定义
    C++入门经典-例5.16-输出引用
    C++入门经典-例5.15-回收动态内存的一般处理步骤
    C++入门经典-例5.14-丢失的内存,关于内存泄漏
    C++入门经典-例5.13-内存安全,被销毁的内存
    C++入门经典-例5.12-动态内存的销毁
    C++入门经典-例5.11-动态分配空间,堆与栈
    C++入门经典-例5.10-指针作为返回值
  • 原文地址:https://www.cnblogs.com/liyongsan/p/5320536.html
Copyright © 2020-2023  润新知