Reset admin password for MySQL and Plesk on CentOS 6 - mysql

I have updated mysql using...
wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
yum localinstall mysql57-community-release-el6-7.noarch.rpm
yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql55-community
yum update mysql-server
Everything went fine. But then when I tried to update the tables etc with
mysql_upgrade -u root -p
I got
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Error: Failed while fetching Server version! Could be due to unauthorized access.
FATAL ERROR: Upgrade failed
I tried
mysql_upgrade -uadmin -p
and
mysql_upgrade -uadmin -p`cat /etc/psa/.psa.shadow`
after reading that this was what was needed for Plesk, but it had the same result.
mysqlcheck --all-databases --check-upgrade --auto-repair
gave
mysqlcheck: Got error: 1045: Access denied for user 'root'#'localhost' (using password: NO) when trying to connect
At this point I checked passwords but I thought they were correct.
At this point I messed up when trying to change/update/reset the password in mysql. I followed code I found online...
cp /etc/psa/.psa.shadow /etc/psa/.psa.shadow.bak # just backup
chmod 400 /etc/psa/.psa.shadow.bak # just secure backup
echo "PLACE PLAIN PASSWORD OF MySQL user ADMIN HERE" > /etc/psa/.psa.shadow
and also
mysql -uadmin -p'cat /etc/psa/.psa.shadow' mysql -e "update user set Password=password('password') where User='admin'; flush privileges;"
And now I have
Unable to connect to database: mysql_connect(): Access denied for user 'admin'#'localhost' (using password: NO) (Error code: 1045) (Abstract.php:69)
when trying to connect to Plesk.
So I think now my mysql admin password and password in /etc/psa/.psa.shadow do not match? I have been trying to find how to start again by setting a mysql admin password and the same for /etc/psa/.psa.shadow, but at this point I decided to ask for help!
Is there anybody who can help me? :)

So I think now my mysql admin password and password in /etc/psa/.psa.shadow do not match?
Yes, you are right.
You can just set password for MySQL's admin user back from /etc/psa/.psa.shadow like:
mysql -uadmin -pYouCurrentPassword -e "update user set Password=password('string from .psa.shadow') where User='admin'; flush privileges;"
After this it's should be possible to login to plesk and change password to new one if you need.

Related

Bitnami server: Reset the MySQL root password

I don’t remember my MySQL root password used in 'Bitnami WordPress Stack' (wordpress-5.4.2-0) in Linuy-Mint and tried the steps described here:
https://docs.bitnami.com/installer/apps/wordpress/administration/change-reset-password/
explicitly:
nano installdir/mysql/tmp/mysql-init
and saved it with:
ALTER USER 'root'#'127.0.0.1' IDENTIFIED BY 'NEW_PASSWORD';
then i restarted the MySQL server via Bitname App installdir/manager-linux-x64.run
i expected to be able in:
http://127.0.0.1:8080/phpmyadmin/index.php
with user root and NEW_PASSWORD but get then this error-message:
mysqli::real_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES)
This way is different to suggestions on: Bitnami. reset mysql root pwd
i tried also:
~/wordpress-5.4.2-0/mysql$ service mysql reset-password
mysql: unrecognized service
~/wordpress-5.4.2-0/mysql$ sudo dpkg-reconfigure mysql-server-x.x
and get the same errors in phpmyadmin.
if i use:
sudo /usr/bin/mysqld_safe --skip-grant-tables & mysql -h localhost
it got
Command 'mysql' not found, but can be installed
but of course its installed.

Unable to log into mysql using password - Ubuntu

I installed mysql in Ubuntu 20.04.
Problem -
Case 1: I have default root user. I can login using sudo mysql but cannot login using mysql -u root -p.
Case 2: I created another user 'local'. I can login using mysql -u local -p and by giving password I set. But problem is if I give wrong password, it still logs me in. I don't know why.
I followed this ERROR 1698 (28000): Access denied for user 'root'#'localhost'
but this didn't help me. I followed other topics too like creating new user for mysql etc.
I cannot access from workbench or from python script too.
Error : ERROR 1698 (28000): Access denied for user 'root'#'localhost'
Login to mysql using sudo mysql -u root
Give your su password and it will login without mysql password.
Run following commands:
USE mysql;
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
exit;
Restart:
sudo systemctl restart mysql.service
After that, run commands to secure MySQL server and create a new root password.
sudo mysql_secure_installation
When prompted, answer the following questions :
New password: Enter password
Re-enter new password:
Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
Next time, type following command in terminal to login:
sudo mysql -u root -p
Then type mysql password you set recently to sign in.
Good Luck, this worked for after continuous wasting several hours on this thing and following tens of tutorials.
By doing this, I was finally able to establish connection in workbench and in my python scripts.

How can I successfully login with root after running mysql_secure_installation?

I am currently unable to login as root on mysql and I am not quite sure about what's going on. Here's what happened:
I ran mysql_secure_installation as recommended, to secure my mysql installation. Afterwards, I typed the default root password that was asked and then I entered:
No to setting a password for root
Yes on removing anonymous users
Yes on disallowing remote root login
Yes on removing the test database and access to it
Yes on reloading privilege tables
After completing this process, I tried accessing mysql with mysql -u root -p (entered the default password) and received this message:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
Do you have any ideas on what might have went wrong?
I also tried resetting the root password by starting mysql with --skip-grant-tables, but I am still not able to login.
I am using Ubuntu 14.04 and mysql 14.14 (LAMP stack).
I know this is an old post but the main answer is outdated and did not solve my issue.
Below my steps for future reference if anybody is having similar problems.
Stop mysql if it's running
$ sudo service mysql stop
Start mysql in safe mode
$ sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking
If you get the error
"mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists"
Just create that folder:
$ mkdir -p /var/run/mysqld
$ chown mysql:mysql /var/run/mysqld
Open a new terminal window and log into mysql service + select mysql database:
$ mysql -u root
mysql> use mysql;
Set new password for root user:
mysql> update user set authentication_string=password('new-password') where user='root';
Flush privileges and exit mysql:
mysql> FLUSH PRIVILEGES;
mysql> exit;
Stop the safemode mysql (from the second terminal, you will see it stop in the first terminal)
$ mysqladmin -u root -p shutdown
Restart mysql
$ sudo service mysql start
You should be able to use the root user with password now to login to mysql/phpmyadmin
CentOS/Redhat:
From what I read in docs, when you run mysql_secure_installation, a temporary root password is generated and is stored in some log file.
sudo grep 'temporary password' /var/log/mysqld.log
Debian/Ubuntu:
During the packages installation, you get a prompt asking for the root password. If you don’t set it up, MySQL’s root user is created without a password. We can read the following line in package installation output:
Shell
2016-05-16T07:27:21.532619Z 1 [Warning] root#localhost is created with
an empty password ! Please consider switching off the
--initialize-insecure option.
but it is configured with the auth_socket plugin. You will only be able to connect using the UNIX socket, therefore any attempt to connect using your local IP or the network fails. Later on, you can change the password to allow connections from the network (as explained in this blog post).
Source
All we can do now is to see the root password. Lets change the root password since you cannot understand hashed password even if we can see it:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking
then run mysql in a new terminal
mysql -u root
and run the following query, after changing the password
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;
quit the mysql safe mode and start mysql service by
mysqladmin shutdown
sudo service mysql start
just run this script by root , you need custormize you password
mysqlpassword=password
/usr/bin/mysqladmin -u root password "$mysqlpassword"
#configure mysql login privileges
echo "grant all privileges on *.* to root#\"localhost\" identified by \"$mysqlpassword\";show databases;" |mysql -u root -p$mysqlpassword

Cannot Set Root Password MySQL CentOS 6

Overview
Hi! I'm new to Linux, but I was able to get MySQL installed and running on several VPS; however, I recently reset my VPS by reinstalling CentOS 6. I've run into a problem regarding MySQL where it won't let me log in or set a password. I've never run into this issue before, so I'm hoping for someone to see if they can help me out.
Steps that replicated the issue
yum install wget
wget http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
sudo yum localinstall mysql57-community-release-el6-8.noarch.rpm
yum install mysql mysql-server
/etc/init.d/mysqld start
mysqladmin -u root -p "setpasswordhere"
At the last step it won't let me and tells me to input the current root password, but I was never prompted to set a password in the first case. I've reinstalled the VPS 2-3 times now and done the same procedure that didn't cause me the problems in the past. Albeit reinstalling the entire VPS isn't the greatest thing to do, but in times where I'm completely lost and new to something, reinstalling and starting from scratch only takes about 5-10 minutes.
Research:
I followed some steps for installing MySQL here: https://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/linux-installation-yum-repo.html
The error message is:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
Or
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: YES)'
So obviously a password is set here, but I'm never prompted to create one in the first place.
Console Output:
[root#vps83299 ~]# mysqladmin -u root -p ""
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
[root#vps83299 ~]#
Error when I get when following this instruction: https://ubuntu.flowconsult.at/en/mysql-set-change-reset-root-password/
mysql> update user set password=PASSWORD("newpass") where User='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
For acess mysql, use:
mysqladmin -uroot -psetpasswordhere
or
mysql -uroot -psetpasswordhere
RECOVER MYSQL ROOT PASSWORD( for linux users)
#
Login to root user and run step1 and 2
Step 1# /etc/init.d/mysql stop
Step 2# mysqld_safe --skip-grant-tables &
Output : Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: startedStep # 3: Connect to mysql server using mysql client:
Keep this running................
Step 3
Login to new terminal (with root user)
mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD('NEW-ROOT-PASSWORD') where User='root';
mysql> flush privileges;
mysql> quit
Step 4 # Stop MySQL Server:
/etc/init.d/mysql stop
Step 5 # /etc/init.d/mysql start
mysql -u root -pNEWPASSWORD
--------------------- completed----------

Unable to login to MySQL

I installed MySQL using the following command:
sudo apt-get install mysql-server mysql-client mysql-common
It asks me for a root password (On package configuration), I enter one and confirm it.
sudo /etc/init.d/mysql start
However when I try logging in to mysql with user root and password which I supplied in the previous step, it denies me access:
root#mbilwebh02:/etc# > mysql --user root --password
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES).
Another attempt that I made was to uninstall and reinstall mysql without supplying a password but that fails as well.
I then switched the user on the server to mysql
root#mbilwebh02:/etc# sudo -u mysql -s
root#mbilwebh02:/etc# sudo -u mysql -s
bash: /root/.bashrc: Permission denied
mysql#mbilwebh02:/etc$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
At this point I am able to only start and stop mysql. Any ideas where I might be going wrong?
[EDIT]
After searching a lot I found that one can log in to mysql using debian-sys-maint as user and password which is in the debian.cnf file. There was no 'root' user in the mysql database hence everything I tried denied me access.
I do not know if this is a safe way to do it though.
Taken from: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.
Connect to the mysqld server with this command:
shell> mysql
Issue the following statements in the mysql client. Replace the password with the password that you want to use.
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
You should now be able to connect to the MySQL server as root using the new password. Stop the server, then restart it normally (without the --skip-grant-tables and --skip-networking options).