• MySQL的存储引擎(二)解决Warning Code : 3719 'utf8' is currently an alias for the character set UTF8MB3,...


    1.外键约束:MySQL支持外键的常用存储引擎只有InnoDB,在创建外键的时候,要求父表必须有对应的索引,子表在创建外键的时候也会自动创建对应的索引。

    CREATE TABLE country(
        country_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
        country VARCHAR(50) NOT NULL,
        last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        PRIMARY KEY (country_id)
    ) ENGINE=INNODB DEFAULT CHARSET=utf8;
    
    CREATE TABLE city (
        city_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
        city VARCHAR(50) NOT NULL,
        country_id SMALLINT UNSIGNED NOT NULL,
        last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        PRIMARY KEY (city_id),
        KEY idx_fk_country_id (country_id),
        CONSTRAINT fk_city_country FOREIGN KEY (country_id) REFERENCES country (country_id) ON DELETE RESTRICT ON UPDATE CASCADE 
    ) ENGINE=INNODB DEFAULT CHARSET=utf8;

     1 warnings:

    Warning Code : 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.

    查看下mysql字符集

     SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

    修改默认字符集例句:
    CREATE
    DATABASE IF NOT EXISTS database_name DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci
    CREATE TABLE city1 (
        city_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
        city VARCHAR(50) NOT NULL,
        country_id SMALLINT UNSIGNED NOT NULL,
        last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        PRIMARY KEY (city_id),
        KEY idx_fk_country_id (country_id),
        CONSTRAINT fk_city_country FOREIGN KEY (country_id) REFERENCES country (country_id) ON DELETE RESTRICT ON UPDATE CASCADE 
    ) ENGINE=INNODB DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci

    不再报错:

     

  • 相关阅读:
    由于挂载的nfs存储目录掉下线,导致创建VM时,无法创建
    使用RVM更新Ruby 版本
    安装logstash+kibana+elasticsearch+redis搭建集中式日志分析平台
    Topic modeling【经典模型】
    [第1集] 课程目标,数据类型,运算,变量
    Juint test Case 的2种使用方式
    getJSON方式请求服务器
    Web项目改名的带来的404not found问题
    JavaWeb EL表达式, JSTL标签及过滤器综合学习
    HashMap的几种遍历方式(转载)
  • 原文地址:https://www.cnblogs.com/kate7/p/13299006.html
Copyright © 2020-2023  润新知