Can't connect to MySQL localhost (how to)

Questions regarding the Database Server
MySQL, PostgreSQL, MariaDB, Percona Server, phpMyAdmin, phpPgAdmin
Aldoseri
Posts: 7
Joined: Fri Nov 25, 2016 12:08 pm

Can't connect to MySQL localhost (how to)

Postby Aldoseri » Sat Dec 10, 2016 11:07 pm

Hi guys,

I thought this might help someone.

If you get this message from VestaCP ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Then this means your root password for MySQL has changed for example after installing MariaDB. like in my case where I used a password different from when I first Installed VestaCP.

Steps to fix the problem.

1- Login to your server using FTP
2- Update your password in the following files.

/root/.my.cnf
/usr/local/vesta/conf/mysql.conf

You don't need to restart your server or MySQL service.

If you don't know your root password or would like to change it then continue to step 3

3- Follow the instructions below:

login as root using terminal ( I use Mac, maybe you have something else )

~# /etc/init.d/mysqld stop
~# mysqld_safe –skip-grant-tables &
~# mysql -u root
~# mysql> use mysql;
~# mysql> update user set password=PASSWORD(“Your-new-password-here”) where User=’root’;
~# mysql> flush privileges;
~# mysql> quit
~# /etc/init.d/mysqld stop
~# /etc/init.d/mysqld start

Now it should work

Thanks

skurudo
VestaCP Team
Posts: 7711
Joined: Fri Dec 26, 2014 2:23 pm
Location: Moscow
Contact:

Re: Can't connect to MySQL localhost (how to)

Postby skurudo » Mon Feb 27, 2017 9:34 pm

Nice one! Thanks.

PS: Topic it's sticky now.
-> DigitalOcean competition - please, support us
-> fix for phpmyadmin - nice and sweet now

sifur
Posts: 21
Joined: Mon Dec 28, 2015 10:43 pm

Re: Can't connect to MySQL localhost (how to)

Postby sifur » Mon Aug 14, 2017 11:29 am

I followed your all steps above, but it's not working for me.

I'm having issue with creating new database in VestaCP.
It's showing error message:

Code: Select all

Error: Connection to localhost failed


What I did?
I don't have much knowledge on server of course, and by curious-
> I changed DB password from Server > Configure > DB > Password. I thought as this options is here it should change MySQL password without problem.
> After 3/4 days when I try add new Database, I'm getting this error.
> Then I searched here and google then tried many things. to reset mysql root password.
> Here when I try this mysql -u root it's showing this error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I'm using Ubuntu 16 with latest vestacp installed 3 months ago.
Now I have 5 sites running on the server and that's why I can't simply uninstall or reinstall vesta again.


Return to “Database Server”



Who is online

Users browsing this forum: No registered users and 2 guests