How do I delete a column from an existing MySQL table using UNIX / Windows / Linux mysql command line utility sql syntax?
You need to use the ALTER TABLE syntax to change the structure of an existing table. For example, you can add or delete columns, create or destroy indexes, change the type of existing columns, and much more with ALTER TABLE.
Step # 1: Login to mysql
Type the following command:
mysql -u user -p databasename
Step 2: Delete column
First see table description:
desc tableName
Use the following syntax at mysql>
ALTER TABLE tableName DROP columnName;
For example, see t1 table description, enter:
DESC t1;Sample outputs:
+-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | c1 | int(11) | YES | | NULL | | | c2 | varchar(30) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
Delete column c2, enter:
ALTER TABLE t1 DROP c2; DESC t1
Sample outputs:
+-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | c1 | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 1 row in set (0.00 sec)
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 4 comments… read them below or add one }
I want to delete column data only not row for that i have write that query but it doesn’t work so any idea please share me
DELETE title FROM thinks_books WHERE title=’urdu’,
Thanks
Azeem Akram
Dear Azeem, try to execute “UPDATE ” query instead of DELETE
UPDATE thinks_books SET title=” ” WHERE title=’Urudu’;
I created a table in mysql containing 2 columns ,userid,movieid.I entered the values in movieid column using arraylist.
the table contains the following data
userid movieid
1 12234,5688,8976
2 567
now i want to delete 12234 in movieid column where userid=1
how i can write the query in mysql.can anyone help me.
how to show agin table