zoukankan      html  css  js  c++  java
  • MySQL 查看编码 排序规则

    查看数据库的排序规则

    mysql> show variables like 'collation%';
    +----------------------+-------------------+
    | Variable_name        | Value             |
    +----------------------+-------------------+
    | collation_connection | utf8_general_ci   |
    | collation_database   | utf8_general_ci   |
    | collation_server     | latin1_swedish_ci |
    +----------------------+-------------------+
    3 rows in set (0.00 sec)

    查看数据库的编码格式

    mysql> show variables like 'char%';
    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | utf8                       |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | latin1                     |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)

    查看字段的排序规则

    mysql> show create table tablename;

    查看表字段信息

    mysql> desc tablename;

    查看当前数据库编码

    mysql> use databasename;
    Database changed
    
    mysql> show variables like 'character_set_database'; 
    +------------------------+-------+
    | Variable_name          | Value |
    +------------------------+-------+
    | character_set_database | utf8  |
    +------------------------+-------+
    1 row in set (0.03 sec)

    修改当前数据库的编码

    mysql> use databasename;
    Database changed
    
    mysql> alter database databasename character set latin1;  #将之前的utf8编码修改为latin1编码
    Query OK, 1 row affected (0.00 sec)
    +------------------------+--------+
    | Variable_name          | Value  |
    +------------------------+--------+
    | character_set_database | latin1 |
    +------------------------+--------+
    1 row in set (0.00 sec)

    查看字段编码

    SHOW FULL COLUMNS FROM tablename;

    修改字段的字符集

    ALTER TABLE tablename CHANGE c_name c_name CHARACTER SET character_name [COLLATE ...];
    如:ALTER TABLE users CHANGE title title VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci;
  • 相关阅读:
    【机器学习】:梯度提升决策树(GBDT)
    【推荐系统】:LFM算法解析
    【SQL】:内连接,自然连接
    【SQL】:保留小数点后几位(除法)
    Ubuntu 18.04:磁盘读取性能不佳
    skynet超时机制实现
    关于 Spring Boot 中创建对象的疑虑 → @Bean 与 @Component 同时作用同一个类,会怎么样?
    记录不存在则插入,存在则更新 → MySQL 的实现方式有哪些?
    记一次线上问题 → 对 MySQL 的 ON UPDATE CURRENT_TIMESTAMP 的片面认知
    WebSocket
  • 原文地址:https://www.cnblogs.com/tdalcn/p/7481492.html
Copyright © 2011-2022 走看看