SQL installation - trouble shooting - mysql

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.

Related

Can't Reset MySQL password on Ubuntu

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:~$

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.

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

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');

How remind password for mysql localhost base at Linux Mint?

I have a little confusing problem. Trying to connect into own localhost sql database. But always got an error with 1045 code:
mysql.connector.errors.ProgrammingError: 1045 (28000):
Access denied for user 'root'#'localhost' (using password: NO)
Pycode:
config = {
'user': 'root', #Tried our username and empty
'password': '', #Tried few always used for learning, empty, and bruteforce with all isalnum letters from secound writed program with connector.Error catcher :P [to twelve string length].
'host': '127.0.0.1', #Tried localhost / Guazowy(from mysql status)
'database': 'outlet_refactor',
'raise_on_warnings': True, #Without this also.
}
serw = mysql.connector.connect(**config)
Also i tryied use other user, other host and passwords, maybe i once set password but forgot these. (I want to learn build database with python, but this problem for start is too enough for me. Over week i trying find solution)
Console send me that same error when try:
mysql -u root -p
Mine mysql serwer is started when i check with:
sudo service mysql status
Output:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since wto 2017-05-30 17:44:08 CEST; 1h 57min ago
Process: 15834 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 15823 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 15833 (mysqld)
CGroup: /system.slice/mysql.service
└─15833 /usr/sbin/mysqld
maj 30 17:44:07 Guazowy systemd[1]: Starting MySQL Community Server...
maj 30 17:44:08 Guazowy systemd[1]: Started MySQL Community Server.
Restart too isn't help
sudo service mysql stop
sudo service mysql start
Even i belive for dpkg to reconfigure/reset password (i tryied, but this is not for this).
I not have temporary generated password from 'MySQL Yum repository, MySQL SUSE repository, or RPM packages directly downloaded from Oracle', so
sudo grep 'temporary password' /var/log/mysql.log #File not exist
sudo grep 'temporary password' /var/log/mysql/error.log
doesn't print anythink, when I checking manually, just confirm grep results.
mysqladmin variables | grep socket #so grep port too isn't working
>>Out:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'guaz'#'localhost' (using password: NO)'
Also i tryied few other methods in similar questions, but no one help with mine problem and now i can't find these. I'll be gratefull for help or any tips to solution :).
Try the followin command:
$ mysqladmin -u root password NEWPASSWORDHERE
As example:
$ mysqladmin -u root password 123456
to test if that is working:
$ mysql -u root -p'123456' -e 'show databases;'
To change your user password:
Conect from terminal to mysql with root:
$ mysql -u root -p
Go to table mysql:
mysql> use mysql;
Change user password:
mysql> update user set password=PASSWORD("123456") where User='guaz';
Flush privilegies:
mysql> flush privileges;
mysql> quit

Access denied for user 'root'#'localhost' (using password: NO) on 'service mysql start'

OS
$ uname -a
Linux aurora 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
MySQL
$ mysqladmin --version
mysqladmin Ver 8.42 Distrib 5.7.16, for Linux on x86_64
Clearly something is trying to log into my mysql server as root upon
service mysql start
but I don't know what it is.
The last line in /var/log/mysql/error.log related to starting the server is:
[Note] Access denied for user 'root'#'localhost' (using password: NO)
How do I figure the offending config file or server or application that is trying to log in as 'root'#'localhost' on startup? What other information can I provide to help to understand and resolve this issue?
Also, I am able to log in as 'root'#'localhost' if I do so explicitly. It's only the [Note] in the error log that is irritating me and that I want to debug.
This is because the mysqladmin cannot login as root.
The guilty is this Systemd unit:
/lib/systemd/system/mysql.service
Which executes this command to see if the daemon is started properly:
ExecStartPost=/usr/share/mysql/mysql-systemd-start post
Which executes:
# mysqladmin ping
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
# echo $?
0
The return value is 0 despite the error message so the daemon is marked as started.
Debian has a file which contains an user to execute unattended operations, to use this file explicitly the previous command must be executed in this manner:
mysqladmin --defaults-file=/etc/mysql/debian.cnf ping
After this explanation I can ignore the line in the error log.