The Alter database processing process is not as scary as alter table, and the processing logic is clear. Sort the information as follows:
1. Check whether the database name is valid
Call check_db_name () (table. cc: 2876) to check whether the database name is valid. Call the check_table_name () (table. cc: 2904) function. The check_table_name function name is misleading. It is actually used to check whether the database name is legal.
2. Check whether the modification is permitted.
Call check_access () (SQL _parse.cc: 4715) to check whether the database exists and whether the user has the permission to modify the database.
3. Database Modification
Call mysql_alter_db () (SQL _db.cc: 685) to modify the database. Call the lock_schema_name () (lock. cc: 767) function to obtain the mutex lock of the schema. Call the write_db_opt () (SQL _db.cc: 313) function to recreate the db. opt file. The content recorded in the db. opt file is the content of the default character set. Then write the binlog.
The above analysis shows that the business logic of the Alter database operation is relatively simple, but the function is also relatively simple. The alter database option can only modify the default charset and default collation.