Error even after starting mysql server with --skip-grant-tables - mysql

I have forgotten the password for mysql server. Even after starting the server with --skip-grant-tables I get the below error.
ER
ROR 1045 (28000): Access denied for user 'ODBC'#'localhost' (using
password: NO)
This is for windows.
Also I get the error even for mysql -u root
What could be the issue?

Here is what you need to do
First ensure that mysqld is not running.
ps aux | grep mysqld
if it is running. Stop it. Then,
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
FLUSH PRIVILEGES;
SET PASSWORD FOR root#'localhost' = PASSWORD('password');

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.

ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES); Can't reset password

As it says in the title; when I do mysql, it says ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO).
I tried doing mysql -u root -p, it says the same thing.
So I wanted to reset my password with sudo mysqld_safe --skip-grant-tables & and when I do, this is showing:
root#xx:~# 200315 17:45:56 mysqld_safe Logging to syslog.
200315 17:45:56 mysqld_safe A mysqld process already exists
and when I do mysql -u root, it still says Access denied for user 'root'#'localhost' (using password: NO) and it quits sudo mysqld_safe --skip-grant-tables.
System is Nginx
And DB is MariaDB.
Thanks
It seems that the mysqld_safe commands did not work.
It might be helpful stopping mysqld (like sudo service mysqld stop or sudo stop systemctl mysql) before the mysqld_safe command.

How to recover mysql root password in MacOS

I start my MAMP and try to connect to my MySQL server via localhost or 127.0.0.1, I tried all the possible password that I think it is correct, but for some reasons it still didn't like it, so I think I forgot it somehow. I need help.
Try #1
Enter all the possible passwords
MySQL -u root -h localhost -p
Enter password: <---I've tried almost 10 possible passwords
I got
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Try #2
Enter possible passwords
MySQL -u root -h localhost
I got
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Try #3
MySQL.server stop
I got
ERROR! MySQL server PID file could not be found!
I'm trying to run this
mysqld_safe --skip-grant-tables &
I got
Try #4
mysqld_safe --skip-grant-tables &
I got
[1] 72194
🌈 ~ 2017-10-04T12:13:42.6NZ mysqld_safe Logging to '/usr/local/var/mysql/BH-MacBook-Pro-15-512GB.local.err'.
2017-10-04T12:13:42.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2017-10-04T12:13:44.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/BH-MacBook-Pro-15-512GB.local.pid ended
Open a new tab
MySQL -u root
I still get
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Try #5
Close my MAMP application, and run this
mysqld_safe --skip-grant-tables &
I got
[1] 72194
🌈 ~ 2017-10-04T12:13:42.6NZ mysqld_safe Logging to '/usr/local/var/mysql/BH-MacBook-Pro-15-512GB.local.err'.
2017-10-04T12:13:42.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2017-10-04T12:13:44.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/BH-MacBook-Pro-15-512GB.local.pid ended
Open a new tab
MySQL -u root
I still get
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I don't what else to try anymore.
I can't really set the root password because I can't even get in.
This is the process of my MySQL
ps aux | grep MySQL
bheng 95850 0.2 1.0 2869440 175404 ?? S 8:48AM 0:00.28 /usr/local/opt/mysql/bin/mysqld --basedir=/usr/local/opt/mysql --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mysql/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/bh-mbp-15-512gb.ad.benu.net.err --pid-file=/usr/local/var/mysql/bh-mbp-15-512gb.ad.benu.net.pid
_mysql 124 0.0 0.0 2864848 4040 ?? Ss 22Sep17 0:32.26 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so
bheng 95863 0.0 0.0 2423384 396 s009 R+ 8:48AM 0:00.00 grep mysql
bheng 95749 0.0 0.0 2448756 2496 ?? S 8:48AM 0:00.03 /bin/sh /usr/local/opt/mysql/bin/mysqld_safe --bind-address=127.0.0.1 --datadir=/usr/local/var/mysql
bheng 66379 0.0 0.1 2696936 9304 ?? S 8:06AM 0:00.51 /Applications/MAMP/Library/bin/mysqld --basedir=/Applications/MAMP/Library --datadir=/Applications/MAMP/db/mysql --plugin-dir=/Applications/MAMP/Library/lib/plugin --log-error=/Applications/MAMP/logs/mysql_error_log.err --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --socket=/Applications/MAMP/tmpmysql/mysql.sock --port=8889
bheng 66263 0.0 0.0 2446708 2100 ?? S 8:06AM 0:00.02 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log
🌈 ~
This is how you can do it in macOS Sierra, probably you install it via pkg and in the system preferences have an icon for MySQL, something like this:
If is up and running open a terminal and run this command:
pgrep -fl mysql
That will help you to find the path of mysqld and the current command used to start the server, the output could be something like this:
6283 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid
Next step is to stop MySQL, you can do this by clicking on the System Preferences menu and click on the Stop MySQL Server button, Once is stoped within a terminal you will need to start again the server but with some extra options, something like this:
sudo /usr/local/mysql/bin/mysqld \
--skip-grant-tables \
--skip-networking \
--user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid
It is indeed the same command from the output of pgrep -fl mysql but in this case, you just need to add:
--skip-grant-tables --skip-networking
After doing that you will notice that the menu from the System Preferences is Green again and MySQL should be up and running, now you can try to login and change password:
mysql -uroot
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR root#'localhost' = PASSWORD('secret');
mysql> FLUSH PRIVILEGES;
mysql> exit
Stop and start again MySQL from the System Preference panel and it should be working now with the new password.
Please follow the steps in same sequence.
Make sure, your MySQL server is down. Execute below command :
mysql.server stop
Then, start MySQL server in safe mode
mysql.server start --skip-grant-tables --skip-networking
Then, connect to MySQL using root user.
mysql -u root
Change the database from none to mysql
MariaDB [(none)]> use mysql;
Database changed
Update both authentication_string and password column with same password as shown below (if you get column not found error then remove one )
MariaDB [mysql]> update user set authentication_string=PASSWORD('password'), password=PASSWORD('password') where user='root';
MariaDB [mysql]> FLUSH PRIVILEGES;
MariaDB [mysql]> quit;
Now, stop everything including MySQL server and MAMP application as well.
And, search for config.inc.php file inside your MAMP folder (you could use command + space and search this file).
You may not have privilege to change this file. After updating the privilege of the file you need to look for $cfg['Servers'][$i]['password'] and update the password value as shown below.
$cfg['Servers'][$i]['password'] = 'password';
Save this file and restart everything in normal mode. And try connecting root user with new password as shown below :
mysql -uroot -ppassword
You have to reset the MySQL root password as follow :
/etc/init.d/mysql stop
/usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR root#'localhost' = PASSWORD('new_password');
mysql> FLUSH PRIVILEGES;
mysql> exit;
service mysql restart
And then, you will be able to connect using :
mysql -u root -p
Your password
Follow those instructions and you should be fine:
https://svendeswan.wordpress.com/2016/01/26/mysql-reset-root-password-without-knowing-it-mac-mamp/
which is based on this one:
https://www.tech-otaku.com/local-server/resetting-mamp-mysql-root-user-password/

ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES) on linux 16.04

I am new to MySQL and trying to start MySQL but I am getting this error. I also saw other solutions for same type of problem but still it is not working.
Here I tried entering my root password on Enter password prompt.
mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
As far as I know the message using password: NO only appears if you simply press Enter instead of typing in the password.
I don't have access to MySQL at the moment but, if I remember correctly, if you don't have a password (which not a good idea), you simply don't use the -p.
Now my problem is solved i followed these things:
Stopped the MySQL service
sudo /etc/init.d/mysql stop
Start MySQL without a password
sudo mysqld_safe --skip-grant-tables &
I got this error
2017-06-20T18:50:06.475664Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
used these commands to fix it:
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
then followed these commands:
sudo mysqld_safe --skip-grant-tables &
mysql -uroot
use mysql;
update user set password=PASSWORD("mynewpassword") where User='root';
flush privileges;
quit
And it started working.

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