Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 768 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I modify the size of column in a MySQL table?

#1
I have created a table and accidentally put `varchar` length as `300` instead of `65353`. How can I fix that?

An example would be appreciated.
Reply

#2
ALTER TABLE <tablename> CHANGE COLUMN <colname> <colname> VARCHAR(65536);

You have to list the column name twice, even if you aren't changing its name.

Note that after you make this change, the data type of the column will be `MEDIUMTEXT`.

---

Miky D is correct, the `MODIFY` command can do this more concisely.

---

Re the `MEDIUMTEXT` thing: a MySQL row can be only 65535 bytes (not counting BLOB/TEXT columns). If you try to change a column to be too large, making the total size of the row 65536 or greater, you may get an error. If you try to declare a column of `VARCHAR(65536)` then it's too large even if it's the only column in that table, so MySQL automatically converts it to a `MEDIUMTEXT` data type.

mysql> create table foo (str varchar(300));
mysql> alter table foo modify str varchar(65536);
mysql> show create table foo;
CREATE TABLE `foo` (
`str` mediumtext
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

I misread your original question, you want `VARCHAR(65353)`, which MySQL can do, as long as that column size summed with the other columns in the table doesn't exceed 65535.

mysql> create table foo (str1 varchar(300), str2 varchar(300));
mysql> alter table foo modify str2 varchar(65353);
ERROR 1118 (42000): Row size too large.
The maximum row size for the used table type, not counting BLOBs, is 65535.
You have to change some columns to TEXT or BLOBs
Reply

#3
Have you tried this?

ALTER TABLE <table_name> MODIFY <col_name> VARCHAR(65353);

This will change the **col_name**'s type to `VARCHAR(65353)`
Reply

#4
```sql
ALTER TABLE {table_name} MODIFY [COLUMN] {column_name} {column_type} {defaults and/or not-null};
```

(Including `COLUMN` is optional.)

**Note:** *if your column was created with `NOT NULL` etc. you may need to specify those in the `MODIFY` statement to avoid losing them.*
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through