MySQL database freezing after 'use'

On the first "use" command after login, MySQL scans database, tables and columns name for auto completion. If you have many db, tables it could take a while.

To avoid that, launch your client with the -A option (or --no-auto-rehash)

mysql -uroot -p -A

You could also add the disable_auto_rehash variable in your my.cnf (in the [mysql] section) if you want to disable it completely. This change does not require a reboot (it is a client, not server, variable).


In my case, the "Reading table information" was taking an unreasonable amount of time. When I ran mysql -e 'show processlist' I discovered that the process that was "hanging" was "Waiting for table metadata lock". This made some sort of sense as I had a long-running query of the form create table from select ... running elsewhere, so on one level I could understand that until that new table was finished being created, the metadata about tables would not be available. (I guess it would be preferable if auto-complete scan just omitted any "incomplete" tables from the meta data query if this were possible.)

Tags:

Mysql

Backup