自动为MySQL中的所有表设置auto_increment

Given a database with hundreds or thousands of tables:

Considering that all tables were empty. Is there a way to automatically set auto_increment to 1 for all tables?

Could try give it a go in PHP? Would have to know all of the table names.

$tableName = array('somename', 'someOtherName', ...);

foreach ($tableName as $key) {
//Do the query
ALTER TABLE $key MODIFY COLUMN id INT auto_increment
}

Pseudo code.. but you get the idea right?

a database with hundreds or thousands of tables

That's likely to be a big mistake.

To do the task, write a Stored Procedure that creates a Cursor walking through information_schema.TABLES and building the SQL needed for each table. Then prepare() and execute() it.

If the SQL is not allowed in a Stored Procedure, then simply SELECT the SQL to show it. Then manually copy and past it into the mysql commandline tool.