@RooTooZ спасибо, дописал
Выкладываю если кому-то понадобится
<?php
$mysqli = new mysqli("localhost", "root", "root", "INFORMATION_SCHEMA", "3306"');
// Получаем все связи
$result_fk_columns = $mysqli->query("SELECT COLUMN_NAME FROM KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = 'YOUR_TABLE'");
while ($row_fk = $result_fk_columns->fetch_row()) $fk_columns[] = $row_fk[0];
// Все колумны
$result_all_columns = $mysqli->query("SELECT COLUMN_NAME FROM COLUMNS WHERE TABLE_SCHEMA = 'YOUR_TABLE'");
while ($row = $result_all_columns->fetch_row()) $columns[] = $row[0];
// Все таблицы из базы которую будем чистить
$result_tables = $mysqli->query("SELECT TABLE_NAME FROM TABLES WHERE TABLE_SCHEMA = 'YOUR_TABLE'");
while ($row = $result_tables->fetch_row()) $tables[] = $row[0];
// Колумны для удаления
foreach($columns as $key => $value)
if(!in_array($value, $fk_columns)) $columns_for_delete[] = $columns[$key];
$mysqli->query("use YOUR_TABLE");
foreach($tables as $key_table => $table){
foreach($columns_for_delete as $key_column => $column_for_delete){
$mysqli->query("ALTER TABLE ".$table." DROP COLUMN ".$column_for_delete."");
}
}
?>