Forgotten MySQL username on ubuntu

Ema4rl picture Ema4rl · Sep 10, 2013 · Viewed 22.4k times · Source

I've forgotten my MySQL owner details. I need a way to find my username. My password will not be a problem. I use Ubuntu 12.04 Linux, and would prefer a command line solution.

Thank you in advance.

Answer

Alma Do picture Alma Do · Sep 10, 2013

Well, then you have a clear way to restore it:

  1. Run your MySQL server with skipping grant tables option.
  2. Log in as root
  3. Run query

    SELECT DISTINCT user FROM mysql.user
    
  4. That's it - you have a list of users. Save it somewhere, then run server normally and try your user names one by one.

Tip: if you want to reset root password, there's a corresponding manual page.