Why do these approaches not reset my Mysql root password? - mysql

I have set a root password, but cannot authenticate with it. How can I reset this password?
~ mysql --version: mysql  Ver 8.0.13 for osx10.14 on x86_64 (Homebrew)
I used these stackoverflow instructions to set a root password and queried the user table to verify the password.
I then tried mysql -u root -p and mysql -u root and got authentication errors.
Command: mysql -u root -p
Authentication error: ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES). I am SURE I am using the correct password.
Command:mysql -u root
Authentication error: Error: ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO).
That led me to this this stackoverflow question and attempted #Lahiru's solution, but got No such file or directory.
I found the Mysql documentation and performed the following: (as outlined in B.6.3.2.3 Resetting Root Password: Generic Instructions)
mysql.server start --skip-grant-tables
Mysql -u root
FLUSH PRIVILEGES
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
Then I got an error:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
Lastly, using the Mysql 8.0 documentation: 13.7.1.10 SET PASSWORD Syntax I tried:
mysql.server start --skip-grant-tables
SET PASSWORD FOR 'root'#'localhost' = '1111';
and get error: ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
I can't try to do this while running the server out of safe mode because it doesn't accept the password I set.
Thanks in advance for any help.

Related

I cant connect mysql

When I try to enter the root user from MySQL Workbench and manually enter it, I get the following error:
your connection attempt failed for user root to the mysql server
Access denied for user 'root'#'localhost' (using password: YES)
I am using mysql -u root code when I want to connect to MySQL via cmd and I get an error in it:
mysql: Unknown operating system character set 'cp857'.
mysql: switch to the default character set of 'utf8mb4'.
ERROR 1045 (28000): Access was denied for the user 'root'#'localhost' (using password: No)
I get a similar error when I try to log in using a password, the only thing that changes is (using password: YES).
What had I better do?
Issue with your password so simply change mysql root password.
here command
mysql -u root
then
mysqladmin -u root password [newpassword]
may help you this.
thanks

How can I restart mysql without getting this error?

sudo service mysql restart
But I get
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I then enter and can enter mysql without any problem.
mysql -u root -h localhost -ppassword databasename
My question is that, can I restart mysql service without getting that error by maybe supplying hostname and password straight away.
somtimes error occurs but changing mysql password can solve the error.
and once you changed your password, you're error free.

Cannot log into any account on mysql from terminal

Ever since running as suggested: https://stackoverflow.com/a/50131831/3310334
alter user 'root'#'localhost' identified with mysql_native_password by 'Gzbz1H!fZ##LyF33IqP$rAS8H#0iNc4lK8l2Md#EHxJyFK2YgfQwiKxz*0#lykWvKdWzhxh6EYKu&6ZPp1#9$%YMPb6EfDPYf2h';
I can't access mysql anymore:
% mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
% sudo mysql
Password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
% mysql
ERROR 1045 (28000): Access denied for user 'theonlygusti'#'localhost' (using password: NO)
% sudo mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I copy/paste my password exactly as I used to (and the password used to be the same).
In fact, I have noticed that any account that I "altered" as above I cannot log into through the terminal anymore, but they work from within Node.js using require('mysql') package.
How can I regain access to the root account without losing all my databases?
I just made the problem probably-worse by running
ALTER USER 'root'#'localhost' IDENTIFIED WITH caching_sha2_password BY 'Gzbz1H!fZ##LyF33IqP$rAS8H#0iNc4lK8l2Md#EHxJyFK2YgfQwiKxz*0#lykWvKdWzhxh6EYKu&6ZPp1#9$%YMPb6EfDPYf2h';
from inside javascript (after connecting as root).
It was successful.
Now I can't connect to root using JavaScript or the terminal.
I just tried following advice: https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
% cat init.sql
ALTER USER 'root'#'localhost' IDENTIFIED BY 'Gzbz1H!fZ##LyF33IqP$rAS8H#0iNc4lK8l2Md#EHxJyFK2YgfQwiKxz*0#lykWvKdWzhxh6EYKu&6ZPp1#9$%YMPb6EfDPYf2h';
% brew services stop mysql
% mysqld --init-file="$PWD/init.sql"
But I still can't connect by literally copy/pasting exactly the same password as above into the password prompt.
I have also tried the other reset method detailed in that link, using --skip-grant-tables:
% kill `cat /usr/local/var/mysql/theonlygustis-MacBook-Pro.pid`
% mysqld --skip-grant-tables
% mysql
> flush privileges;
> ALTER USER 'root'#'localhost' IDENTIFIED BY 'alter user 'root'#'localhost' identified with mysql_native_password by 'Gzbz1H!fZ##LyF33IqP$rAS8H#0iNc4lK8l2Md#EHxJyFK2YgfQwiKxz*0#lykWvKdWzhxh6EYKu&6ZPp1#9$%YMPb6EfDPYf2h';
> flush privileges;
> exit
% kill `cat /usr/local/var/mysql/theonlygustis-MacBook-Pro.pid`
% mysqld
% mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
It also doesn't work.
The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like systems. Alternatively, on any platform, you can reset the password using the mysql client (but this approach is less secure):
Stop the MySQL server if necessary, then restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD. Because this is insecure, if the server is started with the --skip-grant-tables option, it also disables remote connections by enabling skip_networking.
Connect to the MySQL server using the mysql client; no password is necessary because the server was started with --skip-grant-tables:
shell> mysql //or sudo mysql
In the mysql client, tell the server to reload the grant tables so that account-management statements work:
mysql> FLUSH PRIVILEGES;
Then change the 'root'#'localhost' account password. Replace the password with the password that you want to use. To change the password for a root account with a different host name part, modify the instructions to use that host name.
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables option and without enabling the skip_networking system variable).
If does not help. Can see official page
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO) on Windows

when i want start mysql in windwos cmd i got this error
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
what can i do?
mysql -u root -p
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
You can reset your root password. Have in mind that it is not advisable to use root without password.
install MYSQL again and define pass for root and define a user
and after instalation MYSQL work on cmd whit
cd c:\Program Files\MySQL\MySQL Server 5.7\bin>
then
mysql -u myusername -p
then ask my pass and enter the password of this user name(not root password) and it work
other way for run MYSQL is start menu
in start menu find folder that named MySQL and expand it
and run MySQL command line client
you can find your password by
# cat /var/log/mysqld.log | grep password
These errors sometimes due to DNS problem. To fix it, execute mysqladmin flush-hosts to reset the internal DNS host cache.

I have ubuntu installed with mysql .the below error keeps showing up

linux#ubuntu:~$ mysql
ERROR 1045 (28000): Access denied for user 'linux'#'localhost' (using password: NO)
linux#ubuntu:~$ mysql -u -p
ERROR 1045 (28000): Access denied for user '-p'#'localhost' (using password: NO)
linux#ubuntu:~$
I have ubuntu 14. installed with mysql on a virtual machine vmware .
The above error keeps showing up and I only see the solution everywhere on the internet as :
use "mysql -u -p" but still the error occurs.
It should have space, try this:
mysql -u {username} -p
if you didn't configure mysql(setting password for user), then use just
mysql -uroot, You should mention username.
You can set password for default user root by
mysqladmin -uroot password yourpassword
after setting password run
mysql -uroot -pyourpassword