Php – #1045 Cannot Log in to the MySql server from both phpMyAdmin and from command line

mysqlphpphpmyadmin

The problem is I could not remember the root password I set on the XAMPP Security page and because I could not log into PHPmyAdmin and create a database I assumed I should reset the password for the root account. No changes I make in PHPMyAdmin's security page or in the command line seem to bear any positive results for me.

Though it seems this issue has been addressed numerous times already, I've read numerous articles here and on different sites regarding this error and still I find no thread with the answer.

What I have done is repeat a few flavors of the below, numerous times, to get going. I still cannot get into phpMyAdmin or do anything in the command line with the root account.

I have:

  • reset my root Passwords for Windows Systems via a file
    (mysql-init.txt) containing these commands:

    UPDATE mysql.user SET Password=PASSWORD('1234') WHERE User='root';

    FLUSH PRIVILEGES;

  • after turning off MySql, the above commands were run via the command
    line from my XAMPP shell (run as
    administrator), the syntax like so:

    msyqld –init-file:C:\My Website\Xampp\mysql\mysql-init.txt
    Note: the file resides in the mysql folder. I placed it there.

  • I at points I have modified my config.inc.php file, changing the
    password, but with no real different
    outcome.

    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    $cfg['Servers'][$i]['user'] = 'root';
    $cfg['Servers'][$i]['password'] = ''; \ This was changed and matched to changes made to Xampp sec
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['AllowNoPassword'] = true;
    $cfg['Lang'] = '';

  • if i try logging onto the PHPMyadmin webpage with the root account, I
    get "#1045 Cannot log in to the MySQL
    server"

  • if i try logging into mysql from the command line (run as
    administrator), with the command:
    mysql -u root -p
    (password entered)….
    I get the same thing.

  • From the command line i've run this command as well…
    mysqladmin -u root password 1234
    error: "Access denied for user 'root'@'Localhost' (using password: NO)

  • Also did this:
    SET PASSWORD FOR root@localhost = PASSWORD('1234');
    Seemed to work, but i was still not able to sign on using the account (error 1045)

I've heard it mentioned that there are two root accounts. Can anyone explain or point to the most succinct sources on how I am to start up using the database using these accounts?

Also, can any tell me why I'm able to log into the webpage as any random user ID with no password, but root is

locked out. I'm sure it's because the root account is the most powerful account. How does one get back in the door with root since it seems locked out for it's own good (protected from… me). Forgive my lack of understanding on this. I hope someone can educate me. Please if there is one stupid little thing I'm doing wrong, I'd love to hear about it.

Thanks
Neil

Best Solution

About your second item, I believe your syntax is wrong (need an equal sign instead of a colon), so try this:

mysqld --init-file=C:\My Website\Xampp\mysql\mysql-init.txt

About config.inc.php, because you're using the cookie auth_type, there is no point in entering anything in user and password because you'll be presented with a login panel in phpMyAdmin.

A MySQL account is defined by the host, user and password, so there might be many entries for user root (with different host names).