Gatura
Gatura

Reputation: 605

Mysql root password problems

I have installed mysql on a mac 10.7, I am using phpmyadmin to access the mysql database but am getting locked out with an error when i try to login with a username root no password

Login without a password is forbidden by configuration (see AllowNoPassword)

when i put a password root with the same username, i get an error,

#2002 Cannot log in to the MySQL server

What is the root password in mysql and how can i change it.

Upvotes: 1

Views: 7416

Answers (3)

casperl
casperl

Reputation: 79

This is a recurring question/problem with PHPMyAdmin. Today I installed Ubuntu 18.04 with MariaDB and PHPMyAdmin 4.6.6deb5. This is the info that I should have had before my installation of PHPMyAdmin. Though I used MariaDB, I presume this would also apply to MySQL.

The trick is to install PHPMyAdmin after installing MariaDB and BEFORE running mysql_secure_installation. At this state the MariaDB root password is empty. However PHPMyAdmin will not allow you to login as root with an empty password, therefore you have to run mysql_secure_installation from the terminal and set a root password for MariaDB.

In my experience you may have to, no make that WILL HAVE TO, reset the database root password to [NULL] if you already have an existing root password for MariaDB before installing PHPMyAdmin. If you already have a root password for MariaDB, you will have to login from a terminal with mysql -u root -p and enter the root password. Then you have to execute this query in order to set the database root password to null:

SET PASSWORD FOR root@localhost = PASSWORD('');

and only install PHPMyAdmin once the MariaDB password has been set to zero. Then you will again have to execute mysql_secure_installation as root in order to set a strong password for MariaDB.

I suspect that a lot of the confusion with PHPMyAdmin passwords seems to originate due to users not realising that the username/password that PHPMyAdmin refers to are the MySQL/MariaDB database user names and passwords and not any password specific to PHPMyAdmin.

Upvotes: 0

usrNotFound
usrNotFound

Reputation: 2800

As @Jacob mention you need to set you password for security reason but I am using phpmyadmin for study purpose so I change few settings which works for me.

Step 1: Change config.sample.inc.php to config.inc.php

Step 2: Find the line  $cfg['Servers'][$i]['host'] = 'localhost';
                 and change it to 
          $cfg['Servers'][$i]['host'] = '127.0.0.1';

Step 3: Find the line that says 
        $cfg['Servers'][$i]['AllowNoPassword'] = false;
                and change it to 
         $cfg['Servers'][$i]['AllowNoPassword'] = true;

hope that helps. But remember while working with DB always think about the security of you data. So i suggest you to set password and be safe.

Cheers

Upvotes: 3

Jacob
Jacob

Reputation: 43209

/usr/local/mysql/bin/mysqladmin -u root password new_password_here

To change the password to new_password_here in a fresh install. You can then use thtat to login to phpMyAdmin.

phpMyAdmin default is to set AllowNoPassword to false, for security reasons. So you have to set a password first.

Upvotes: 2

Related Questions