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----------
Related
I enter mysql -u root -p and put in my password and get this error, I have uninstalled and reinstalled mysql and changing the password for root but still get this message.
I have looked and looked for solutions but nothing seems to work.
I am trying to enter mysql through my terminal, instead I get get the error above and can't get into mysql even after uninstalling and reinstalling it.
Usually this means that you are using the wrong credentials to connect, try to consult consult the general log file /var/log/mysqld.log to copy the initialization password.
if that doesn't work you can try this approach:
check if MySQL is installed and running on your system sudo service mysql status
Reset the root password:
stop the server: sudo /etc/init.d/mysql stop
start the server in safe mode: sudo mysqld_safe --skip-grant-tables &
try to connect: mysql -u root
reset the root password: UPDATE mysql.user SET authentication_string=PASSWORD('newpassword'), password_expired='N' WHERE User='root';
flush privileges: FLUSH PRIVILEGES;
quit the server: quit
stop the safe mode server: sudo /etc/init.d/mysql stop
now you can start the MySQL server again: sudo /etc/init.d/mysql start
Use the correct credentials to connect (with the new password)
check out previous answers to this problem here and here.
I understand that this is the safest way to change or reset mysql root password. I'm doing it because 8 times out of 10 the installation program won't prompt me for a root password.
So I run commands:
sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysql -u root
use mysql;
Then, depending on your version of mysql or maria you're using you type:
update user set password=PASSWORD("mynewpassword") where User='root';
or
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
In my case I typed the first one. Then I refresh privileges by:
flush privileges; and then I exit out of mysql by typing: quit.
At this point everything went well. Then I restart mysql server by:
sudo /etc/init.d/mysql start
I get "OK" from the terminal. However, when I attempt to log in as root
I get pleasant error message saying:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
I'm 100% confident that I'm typing correct password. Why is this happening ?
Problem resolved by backing up all important data and reinstalling the operating system. As turned out I had some broken packages that affected how mysql authentication worked. Standard steps to fix broken packages was no use so I wiped out HDD and started over.
MySQL was installed without any hiccups and was even prompted for a root password to be set. Now MySQL authentication works like a charm.
Try this out :- It Works for me..!!
Stop the MySQL server process.
service mysql stop
Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password.
mysqld_safe --skip-grant-tables > /dev/null 2>&1 &
Connect to mysql server as the root user. And Setup new mysql root account password.
mysql -u root -e "use mysql; update user set password=PASSWORD('NEW-PASSWORD') where User='root'; flush privileges;"
Exit and restart the MySQL server.
service mysql restart
Note: You may need to wait after mysqld_safe command, before you can run subsequent mysql command.
Now run :- mysql -u root -p
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.
I cannot login to mysql since I forgot (I lost!) the temporary password I received after installing mysql. So I tried the following steps but they didn't help me:
I stopped mysql server
Then I created a file in /usr/local/mysql/support-files/,called restore, in which I wrote this line: SET PASSWORD FOR
root#localhost=PASSWORD('');
Finally I ran this command: sudo mysqld_safe
--init-file=/usr/local/mysql/support-files/restore but it stuck on mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data. However I checked mysql from system preference and it already started (showing "mysql is running")
I tried to login to mysql again with this command mysql -u root, but still I receive the same error: ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Could someone please help me fix this problem ?
Try this
1. stop mysql server
2. sudo mysqld_safe --skip-grant-tables &
3. mysql -u root //it should not ask password
4. use mysql; //change to mysql db
5. update user set password=PASSWORD("secure password") where user='root';
or (depending on mysql version)
update user set authentication_string=password('secure password') where user='root';
6. flush privileges;
7. logout from mysql (quit)
8. start mysql server (mysql -u root -p)
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).