23

I recently made a rather stupid mistake and corrupt my Ubuntu installation. To resolve it, I booted with a live cd and copied the database files over. However, now I have copied the folders from the old installation into the new one, whenever I type "use database_name" it just freezes on this:

mysql> use my_database_name;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

And then freezes without giving the terminal.

Matthew Haworth
  • 395
  • 1
  • 3
  • 7

3 Answers3

36

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).

Paul White
  • 83,961
  • 28
  • 402
  • 634
Maxime Fouilleul
  • 3,525
  • 22
  • 21
3

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.)

wwkudu
  • 131
  • 3
  • I faced a similar issue.. what does Waiting for table metadata lock means? – Mr. Hobo Jul 28 '21 at 08:04
  • 1
    I'm not a MySQL internal guru, but looks like a reasonable explanation here. Basically it wants to alter meta data about a table, i.e. catalog information (not content) but that meta data is locked because of some other process. – wwkudu Jul 29 '21 at 11:40
1

When you copy entire database from other system:

/var/lib/mysql/*

You may chown -R mysql:mysql /var/lib/mysql/* and start service again.

☝ this solved my problem

Rafael Lemos
  • 111
  • 1