Re: cannot connect from mysql client nor PHP, only sudo

From: Jerry Stuckle <jstucklex_at_attglobal.net>
Date: Fri, 10 Feb 2017 09:32:05 -0500
Message-ID: <o7kipo$pnp$1_at_jstuckle.eternal-september.org>


On 2/10/2017 5:04 AM, Jivanmukta wrote:
> Sorry for my English.
>
> I programmed my first application in PHP+MySQL. It was working fine.
> Since a few days I have error connecting to database: Message:
> mysqli::real_connect(): (HY000/1698): Access denied for user
> 'root'_at_'localhost'.
> I tried: "mysql -u root -p -h localhost" and I have "Access denied for
> user root_at_localhost'.
> Command "sudo mysql -u root -p -h localhost" works fine.
> In mysql log I have only access denied.
> Reinstalling mysql doesn't help. mysql_upgrade doesn't help, either.
>
> $ mysql --version
> mysql Ver 14.14 Distrib 5.7.17, for Linux (i686) using EditLine wrapper
>
> Here you have my privileges:
> mysql> show grants for 'root'_at_'localhost';
> +---------------------------------------------------------------------+
> | Grants for root_at_localhost |
> +---------------------------------------------------------------------+
> | GRANT ALL PRIVILEGES ON *.* TO 'root'_at_'localhost' WITH GRANT OPTION |
> | GRANT PROXY ON ''_at_'' TO 'root'@'localhost' WITH GRANT OPTION |
> +---------------------------------------------------------------------+
> 2 rows in set (0,00 sec)
>
> Please help. I would like to avoid reinstalling Ubuntu.
> $ uname -a
> Linux pecet 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:41:41 UTC 2016
> i686 i686 i686 GNU/Linux

Ok, it was working fine. So what changed? Did you install or update some software, for instance? Did you change your password? If it works from sudo but not your userid, do you have two different versions of the mysql CLI installed and accessing different copies (this shouldn't be a problem unless one copy is *very* old). Or do you have two copies of MySQL running with different my.ini files? Again, it shouldn't be a problem unless you really worked at it.

From your output it looks like perhaps you don't have a root password on MySQL. This is very dangerous. But if that is the case, you should be able to access it with just

mysql -u root

with no -p parameter (-h localhost is the default and you shouldn't need it) in either case).

-- 
==================
[Quoted] Remove the "x" from my email address
Jerry Stuckle
jstucklex_at_attglobal.net
==================
Received on Fri Feb 10 2017 - 15:32:05 CET

Original text of this message