user3525290
user3525290

Reputation: 1617

Percona modify table to allow nulls

how do you modify a table to allow nulls using percona.

pt-online-schema-change --modfiy mycolumn default null d=database, t=table

I see the --alter but nothing to modify an existing column.

Upvotes: 0

Views: 526

Answers (1)

greenweeds
greenweeds

Reputation: 554

First of all, you wouldn't HAVE to use pt-online-schema-change to achieve this as you can do it in native SQL (though you may have a reason for asking how to do it with pt-online-schema-change)

For this table:

DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;

CREATE TABLE t1 (
    id   INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(40)
) ENGINE=InnoDB;

You can use this SQL:

ALTER TABLE `test`.`t1` CHANGE COLUMN name name VARCHAR(40) NULL;

Next, though, if you have a good reason to use pt-online-schema-change, for example if the table is very big, then this would be the syntax:

pt-online-schema-change h=127.0.0.1,P=3306,u=user,p=password,D=test,t=t1 --alter "CHANGE COLUMN name name VARCHAR(40) NULL" --execute

Here's the link to the tool's documentation https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html

Upvotes: 0

Related Questions