Add column if not exists in MySQL

SET @dbname = DATABASE();
SET @tablename = 'YourTable';
SET @columnname = 'YourColumn';
SET @columntype = 'YourType' -- Example: CHAR(16) binary;

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, " ADD ", @columnname, " ", @columntype, " ;")
));
PREPARE stmt FROM @command;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;