Updated on 2024-07-02 GMT+08:00

Online Varchar Length Increase

Introduction

Varchar is a set of character data. The native MySQL only supports varchar whose length is no more than 256 bytes. To increase its length to more than 256 bytes, copy data to new tables and lock the tables to prevent data writes during the length increase. Huawei Cloud RDS for MySQL has no limitations on the varchar length and allows you to increase it online.

Supported Versions

You are advised to use the latest minor version. For details about how to upgrade a minor version, see Upgrading a Minor Version.

Table 1 Supported versions for online varchar length increase

Varchar Length

RDS for MySQL 5.6

RDS for MySQL 5.7

RDS for MySQL 8.0

Less than 256 bytes

Not supported

Supported

Supported

From less than 256 bytes to more than 256 bytes

Supported

Supported

Not supported

More than 256 bytes

Not supported

Supported

Supported

Category

  • Increase the varchar length to less than 256 bytes.
    create table t1(a varchar(10));
    Query OK, 0 rows affected (0.03 sec)
    alter table t1 modify a varchar(100),ALGORITHM=INPLACE, LOCK=NONE;
    Query OK, 0 rows affected (0.06 sec)
    Records: 0  Duplicates: 0  Warning: 0
  • Increase the varchar length from less than 256 bytes to more than 256 bytes.
    create table t1(a varchar(100));
    Query OK, 0 rows affected (0.05 sec)
    alter table t1 modify a varchar(300),ALGORITHM=INPLACE, LOCK=NONE;
    Query OK, 0 rows affected (0.11 sec)
    Records: 0  Duplicates: 0  Warning: 0
  • Increase the varchar length beyond 256 bytes.
    create table t1(a varchar(300));
    Query OK, 0 rows affected (0.08 sec)
    alter table t1 modify a varchar(500),ALGORITHM=INPLACE, LOCK=NONE;
    Query OK, 0 rows affected (0.06 sec)
    Records: 0  Duplicates: 0  Warning: 0