Drop column if exists in MySQL

Below command will drop the column if exists from a given table:

SET @dbname = DATABASE();
SET @tablename = 'YourTable';
SET @columnname = 'YourColumn';


SET @command = (SELECT IF(
  (
    SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
    WHERE
      (table_name = @tablename)
      AND (table_schema = @dbname)
      AND (column_name = @columnname)
  ) <= 0,
  "SELECT 1",
  CONCAT("ALTER TABLE ", @tablename, " DROP COLUMN ", @columnname, " ", " ;")
));
PREPARE command FROM @command;
EXECUTE command;
DEALLOCATE PREPARE command;