'; if(!$mysql = mysqli_connect($host, $user, $pass, '', $port)) { die('Cant connect to DB. ' . mysqli_error($mysql)); } //Set here the schemas you want to scan $schemas = [ 'schema_1', 'schema_2', ]; foreach ($schemas as $s) { echo "/*********$s schema**********/$eol"; $tableQuery = $mysql->query("SHOW TABLES FROM $s"); while ($t = $tableQuery->fetch_array(MYSQLI_NUM)) { $tableFullname = "`$s`.`$t[0]`"; $columnQuery = $mysql->query("SHOW FULL COLUMNS FROM $tableFullname"); while ($c = $columnQuery->fetch_object()) { if(strstr($c->Type, 'zerofill') !== false) { echo getAlter($tableFullname, $c) . $eol; } } } } function getAlter($table, $col) { $newType = str_replace('zerofill', '', $col->Type); return "ALTER TABLE $table MODIFY COLUMN $col->Field $newType $col->Extra " . ($col->Null === 'NO' ? 'NOT' : '') . " NULL " . ($col->Default !== null ? "DEFAULT $col->Default" : "") . " " . ($col->Comment ? "COMMENT '$col->Comment'" :"") . ";"; }