forget the temporary mysql passowrd - mysql

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)

Related

Can't connect to mysql, get this error: ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)

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.

How to install mysql properly

I am trying to install mysql in my macbook pro (OS version: 10.15.2).
These are the steps I followed
Install mysql community server from this link
Install mysql workbench from this link
Open mysql from system preferences and click initialize database
set password for root user under initialize database
open .bash_profile through terminal and set path for mysql
export PATH=${PATH}:/usr/local/mysql/bin/
restart terminal to start mysql server with the following command
mysql -u root -p
enter the password set for root user from step 4
After all this I get the following error
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
Not sure what I am doing wrong.
This is the video I followed to install mysql in my system
[EDIT 1]
staring server with -skip-grant-tables
sudo mysqld_safe --skip-grant-tables
OUTPUT
2020-02-25T05:27:00.6NZ mysqld_safe Logging to '/usr/local/mysql/data/SASHAANKs-MacBook-Pro.local.err'.
2020-02-25T05:27:00.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2020-02-25T05:27:02.6NZ mysqld_safe mysqld from pid file /usr/local/mysql/data/SASHAANKs-MacBook-Pro.local.pid ended
I believe the default authentication mechanism in MySQL 8 is auth socket. Try setting the root password like this:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'my_password';
More on this here: https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
If you can't access the CLI interface at all you should try manually resetting the root password as outlined here: https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
Restart the mysql server with the --skip-grant-tables option.
Connect to the CLI (no password should be necessary)
FLUSH PRIVILEGES;
Reset root password as described above: ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'my_password';
Restart mysql normally

Resetting mysql root password

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

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----------

How to reset MySQL root password in OSX? Popular method does not work

I cannot login as root#localhost in MySQL.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I have tried the following method which I suppose most of the users would have heard of:
stop mysql
mysqld_safe --skip-grant-tables
login as mysql -u root
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES
quit
This won't work. Is there any other suggestion?
After I login in step 3, when I SELECT * FROM mysql.user, the result is empty. It seems that there is no root user.
OS: OS Yosemite. I use the MySQL comes natively with the Macbook Pro.
The problem seems to occur when I try to change the connecting socket from /tmp/mysql.sock to /var/mysql/mysql.sock
Thank you very much.
I've found the following command's work on my MySQL installation in Yosemite.
Stop MySQL
mysqld_safe --skip-grant-tables
login as mysql -u root
use mysql;
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;
Quit MySQL and restart as normal
you could try mysql_install_db in the terminal , this will create system tables and should restore root password to default which is nothing. see if it has any other implications that affects you here.