I followed this guide for installing mysql on ubuntu (accessed via ssh), but I got the error ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES) after setting root to use mysql_native_password. I tried many guides for resetting the password, but I got other errors when doing so:
ubuntu#ip-my-ip-addr:~$ sudo apt update
ubuntu#ip-my-ip-addr:~$ sudo apt install mysql-server
ubuntu#ip-my-ip-addr:~$ sudo systemctl start mysql.service
ubuntu#ip-my-ip-addr:~$ sudo mysql_secure_installation
ubuntu#ip-my-ip-addr:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
ubuntu#ip-my-ip-addr:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
ubuntu#ip-my-ip-addr:~$ sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.41-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
ubuntu#ip-my-ip-addr:~$ sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.41-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | | auth_socket | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *D777F42287F9A654F63676430A68018AABBACE40 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY ‘my_password-(sameasadminpassword)’;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | *14585CD1271D95EF99B6170050F18E6C49EE2BD2 | mysql_native_password | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *D777F42287F9A654F63676430A68018AABBACE40 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)
mysql> exit
Bye
ubuntu#ip-my-ip-addr:~$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
ubuntu#ip-my-ip-addr:~$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
ubuntu#ip-my-ip-addr:~$ sudo service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-02-17 15:03:40 UTC; 24min ago
Main PID: 2930 (mysqld)
Tasks: 29 (limit: 1134)
CGroup: /system.slice/mysql.service
└─2930 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Feb 17 15:03:40 ip-my-ip-addr systemd[1]: Starting MySQL Community Server...
Feb 17 15:03:40 ip-my-ip-addr systemd[1]: Started MySQL Community Server.
ubuntu#ip-my-ip-addr:~$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
ubuntu#ip-my-ip-addr:~$ sudo mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ubuntu#ip-my-ip-addr:~$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
ubuntu#ip-my-ip-addr:~$ sudo systemctl stop mysql
ubuntu#ip-my-ip-addr:~$ sudo mysqld_safe --skip-grant-tables
2023-02-17T15:34:58.081851Z mysqld_safe Logging to syslog.
2023-02-17T15:34:58.085719Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2023-02-17T15:34:58.089306Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
ubuntu#ip-my-ip-addr:~$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ubuntu#ip-my-ip-addr:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
ubuntu#ip-my-ip-addr:~$ sudo mysqld --skip-grant-tables &
[1] 4263
ubuntu#ip-my-ip-addr:~$ mysql -u root mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[1]+ Exit 1 sudo mysqld --skip-grant-tables
ubuntu#ip-my-ip-addr:~$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ubuntu#ip-my-ip-addr:~$ sudo mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ubuntu#ip-my-ip-addr:~$ sudo systemctl stop mysql
ubuntu#ip-my-ip-addr:~$ sudo usermod -d /var/lib/mysql/ mysql
ubuntu#ip-my-ip-addr:~$ sudo systemctl start mysql
ubuntu#ip-my-ip-addr:~$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
ubuntu#ip-my-ip-addr:~$ sudo mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ubuntu#ip-my-ip-addr:~$ sudo grep 'temporary password' /var/log/mysqld.log
grep: /var/log/mysqld.log: No such file or directory
ubuntu#ip-my-ip-addr:~$ sudo service mysql stop
ubuntu#ip-my-ip-addr:~$ sudo mysqld_safe --skip-grant-tables --skip-networking
2023-02-17T15:42:17.816960Z mysqld_safe Logging to syslog.
2023-02-17T15:42:17.820925Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2023-02-17T15:42:17.824572Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
ubuntu#ip-my-ip-addr:~$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ubuntu#ip-my-ip-addr:~$ sudo mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ubuntu#ip-my-ip-addr:~$ sudo systemctl stop mysql
ubuntu#ip-my-ip-addr:~$ sudo usermod -d /var/lib/mysql/ mysql
usermod: no changes
ubuntu#ip-my-ip-addr:~$ sudo systemctl start mysql
ubuntu#ip-my-ip-addr:~$ sudo mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ubuntu#ip-my-ip-addr:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
ubuntu#ip-my-ip-addr:~$ sudo systemctl stop mysql
ubuntu#ip-my-ip-addr:~$ sudo mysqld --skip-grant-tables &
[1] 4905
ubuntu#ip-my-ip-addr:~$ mysql -u root mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[1]+ Exit 1 sudo mysqld --skip-grant-tables
ubuntu#ip-my-ip-addr:~$ sudo systemctl restart mysql
ubuntu#ip-my-ip-addr:~$ mysql -u root mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ubuntu#ip-my-ip-addr:~$
Related
T he version installed on my machine.Details as follows:
mandar#~:$ mysql --version
mysql Ver 8.0.31-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
mysql is running ---
mandar#~:$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-01-11 12:53:58 IST; 7min ago
Process: 180517 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 180525 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 37674)
Memory: 364.3M
CPU: 2.622s
CGroup: /system.slice/mysql.service
└─180525 /usr/sbin/mysqld
Jan 11 12:53:56 coeus systemd[1]: Starting MySQL Community Server...
Jan 11 12:53:58 coeus systemd[1]: Started MySQL Community Server.
mandar#~:$ sudo mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I am not able to get mysql prompt .. I have not set any password .
mandar#~:$ sudo mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I have tried to start sql in safe mode using following command
sudo mysqld_safe --skip-grant-tables &
Error Message
mandar#~:$ 2023-01-11T06:19:33.781251Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2023-01-11T06:19:33.782132Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
I also tried to complete the secure installation
mandar#~:$ sudo mysql_secure_installation
[sudo] password for mandar:
Securing the MySQL server deployment.
Enter password for user root:
Error: Access denied for user 'root'#'localhost' (using password: YES)
mandar#~:$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
what am I doing wrong ?
If you haven't set the password and the username is root try
mysql -u root -p
it will ask for password press enter without typing anything, if you are using ubuntu:
sudo mysql -u root -p
You can follow the Digital Ocean Tutorial for step by step installation guide.
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');
Currently running Ubuntu 16.04, and have just installed MySQL using
sudo apt-get install mysql-client mysql-server
The root password was left empty when prompted. Accessing using
mysql -u root
produces an error:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
However, when using sudo, it works just fine:
sudo mysql
# omitted welcome message
mysql>
mysql> -- When prompting for current user:
mysql> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root#localhost |
+----------------+
Why is access denied using mysql -u root?
Use the below command
mysql -uroot -p
Press Enter
Then it expects a password. If password is not set, then Press Enter again.
I am new to MySQL, and I got some general problems and thanks for any help:
My OS is MAC SnowLeopard, and when I type 'mysql' in terminal, I could successfully go into the mysql system, but, I have no rights to create databases:
mysql> create database A;
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'a'
I tried command line 'mysql -u root', I got the following:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I was thinking that I may set up the username for the database, which made me not possible enter mysql using root as username?
Then I tried 'localhost' as username, which I guess or remember I set it or not, using the command 'mysql -u localhost', I could successfully logged in to mysql, but STILL, cannot create database,
mysql> create database a;
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'a'
I am not sure:
why root not working;
weather I set up the username and password myself before...sorry...really have no memory now.
If I have set up the username as 'localhost' before, I cannot remember the password, therefore I have no rights to create database?
What should I do to recover the password, in the case of no root access?
If not possible, how to uninstall it? The PATH in .bash_profile for mysql is /usr/local/mysql/bin
I got a check: sudo port list installed | grep mysql
mysql5 #5.1.65 databases/mysql5
mysql5 #5.1.65 databases/mysql5
py26-mysql #1.2.3 python/py-mysql
does the mysql in /usr/local/mysql/bin refer to this one listed here?
Edit
The result of running ps -ef | grep mysql:
0 107 1 0 0:00.01 ?? 0:00.02 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/XXX-MacBook-Pro.local.pid
74 245 107 0 0:03.51 ?? 0:18.35 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/mysql/plugin --user=mysql --log-error=/usr/local/mysql/data/XXX-MacBook-Pro.local.err --pid-file=/usr/local/mysql/data/XXX-MacBook-Pro.local.pid
501 3790 417 0 0:00.00 ttys000 0:00.00 grep mysql
501 3337 1271 0 0:00.00 ttys001 0:00.01 mysql -u localhost
You'll need to reset your root password. To do this, follow those simple steps:
Stop MySQL: sudo port unload mysql5-server
Start MySQL using /opt/local/lib/mysql5/bin/mysqld_safe --skip-grant-tables &
Connect to MySQL: mysql -uroot
Reset your MySQL password:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Stop MySQL again sudo killall -9 mysqld_safe
Restart MySQL normally sudo port load mysql5-server
Connect to MySQL: mysql -uroot -p
EDIT
Added commands to stop/start MySQL.
So I'm not sure what caused this to scramble my MySql password (upgrade to Mountain Lion, reinstalling ruby/rails (other issues), or simply just bad luck) but here we are:
Logging in to mysql is fine, but I can't log into the root
Ayman$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 96
Server version: 5.5.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
When I try to login to root:
Ayman$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
Looked at the users:
mysql> CREATE USER root#localhost IDENTIFIED BY 'out22out';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
mysql> SELECT USER(),CURRENT_USER();
+-----------------+----------------+
| USER() | CURRENT_USER() |
+-----------------+----------------+
| Ayman#localhost | #localhost |
+-----------------+----------------+
1 row in set (0.00 sec)
mysql> SELECT USER, HOST FROM mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''#'localhost' for table 'user'
mysql> select user, host from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''#'localhost' for table 'user'
mysql> grant all on *.* to Ayman#'%';
ERROR 1045 (28000): Access denied for user ''#'localhost' (using password: NO)
mysql>
I've tried reinstalling MySql (not sure how to uninstall it), stopping the server instance and restarting it, and every other suggestion on the myriad of similar questions to the right. I've been on this for 3 days now and it's killing me.
Any clue?
You can start MySQL (the server, not the command line monitor) with --skip-grant-tables, which shuts off the permissions systems temporarily. That'll let you get in, update your accounts/passwords without those screwed up permissions getting in the way. Once things are fixed, you do a flush privileges; to re-enable the permissions system.
Ok I figured it out using the tutorial on this website:
I had no clue how to run skip grant tables as evidenced below:
Last login: Wed Aug 22 23:10:42 on console
Ayman$ --skip-grant-tables
-bash: --skip-grant-tables: command not found
Ayman$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Ayman$ --skip-grant-tables
-bash: --skip-grant-tables: command not found
Here is where I googled Skip Grant Tables and found the tutorial listed above:
Don't think any of the initial part of the tutorial worked:
Ayman$ # vi /etc/rc.d/init.d/mysql
Ayman$ $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
[1] 302
Ayman$ $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid- file=$server_pid_file $other_args >/dev/null 2>&1 &
[2] 303
[1] Exit 127 $bindir/mysqld_safe --datadir=$datadir --pid- file=$server_pid_file $other_args > /dev/null 2>&1
Ayman$ mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[2]+ Exit 127 $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir - -pid-file=$server_pid_file $other_args > /dev/null 2>&1
Ayman$ # service mysql start
Ayman$ mysql -u root mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Ayman$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
HERE IS THE MAGIC!:
Ayman$ mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> UPDATE user SET password=PASSWORD('newpassword') WHERE user='root';
Query OK, 4 rows affected (0.11 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges
-> ;
Query OK, 0 rows affected (0.00 sec)
More stuff from the link above that didn't work:
mysql> service mysql stop
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'service mysql stop' at line 1
mysql> # service mysql stop
mysql> # vi /etc/rc.d/init.d/mysql
mysql> $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
->
-> ;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
ERROR:
Can't connect to the server
mysql> $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid- file=$server_pid_file $other_args >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
ERROR:
Can't connect to the server
mysql> $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid- file=$server_pid_file $other_args >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ERROR:
Can't connect to the server
mysql> $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ERROR:
Can't connect to the server
IT's ALIVE!!!!:
mysql> quit
Bye
Ayman$ mysql -u root -p
Enter password: newpassword
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.5.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Thank you to MARC B and the StackOverflow community for pointing me in the right direction and getting this novice back in the game!!