Mysql Access Denied error after server crash - mysql

Our Server crashed with a power failure. After restarting, we are not able to log in to mysql.
mysql -uxxxx -pxxx gives the error:
ERROR 1045 (28000): Access denied for user 'xxxx'#'localhost' (using
password: YES)
We ran namp localhost nad the output was
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
23/tcp open telnet
80/tcp open http
443/tcp open https
3306/tcp open mysql
Gave service mysqld restart and got this error.
Stopping MySQL: [ OK ]
Initializing MySQL database: [ OK ]
Timeout error occurred trying to start MySQL Daemon.
Starting MySQL: [FAILED]
mysqld log file has this:
130309 11:56:10 mysqld started
/usr/libexec/mysqld: ready for connections.
Version: '4.1.7' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
and there is enough space in harddisk.
i am sure we are giving the correct password. Any suggestions would be really helpful.

Run these :
$ service mysqld stop; mysqld_safe &
Then read these. Post your findings
# tail -n 60 /var/log/messages
# tail -n 60 /var/log/mysqld.log
# tail -n 60 /var/lib/mysql/*.err
# tail -n 60 /var/log/mysql/error.log

Related

Creating username & password using script in mysql fails with ERROR 1045 (28000): Access denied

Below is my running mysql instance:
sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2022-09-22 16:49:09 UTC; 9s ago
Process: 229030 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 228946 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
Process: 228921 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 228984 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 24879)
Memory: 390.6M
CGroup: /system.slice/mysqld.service
└─228984 /usr/libexec/mysqld --basedir=/usr
Sep 22 16:49:08 SGGS systemd[1]: Starting MySQL 8.0 database server...
Sep 22 16:49:09 SGGS systemd[1]: Started MySQL 8.0 database server.
Below are mysql packages that are installed.
$ yum list installed | grep mysql
mysql.x86_64 8.0.26-1.module_el8.4.0+915+de215114 #appstream
mysql-common.x86_64 8.0.26-1.module_el8.4.0+915+de215114 #appstream
mysql-errmsg.x86_64 8.0.26-1.module_el8.4.0+915+de215114 #appstream
mysql-server.x86_64 8.0.26-1.module_el8.4.0+915+de215114 #appstream
Below are the configuration files:
$ cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
and
$ ls -ltr /etc/my.cnf.d
total 12
-rw-r--r--. 1 root root 295 Dec 17 2020 client.cnf
-rw-r--r--. 1 root root 565 Sep 1 2021 mysql-default-authentication-plugin.cnf
-rw-r--r--. 1 root root 612 Sep 1 2021 mysql-server.cnf
$ cat /etc/my.cnf.d/*
#
# These two groups are read by the client library
# Use it for options that affect all clients, but not the server
#
[client]
# This group is not read by mysql client library,
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]
#
# MySQL 8.0.4 introduced 'caching_sha2_password' as its default authentication plugin.
# It is faster and provides better security then the previous default authentication plugin.
#
# Until now (09/2018), it does not work with some other software (eg. MariaDB client, MariaDB connectors, ...)
#
# This configuration file changes MySQL default server configuration, so it behaves the same way as in MySQL 5.7.
#
# To change the behaviour back to the upstream default, comment out the following lines:
[mysqld]
default_authentication_plugin=mysql_native_password
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
Right after setup I wrote and ran the below script to create user and Database:
$ cat mysql.create
PASSWDDB="NGPASS#12"
MAINDB="NGSGGS_DB"
mysql -P 3306 -e "CREATE DATABASE ${MAINDB} /*\!40100 DEFAULT CHARACTER SET utf8 */;"
mysql -P 3306 -e "CREATE USER ${MAINDB}#localhost IDENTIFIED BY '${PASSWDDB}';"
mysql -P 3306 -e "GRANT ALL PRIVILEGES ON ${MAINDB}.* TO '${MAINDB}'#'localhost';"
mysql -P 3306 -e "FLUSH PRIVILEGES;"
However, running the script got me the below error:
$ ./mysql.create
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Note: This is a plain fresh installation and I have not made any significant changes to the database.
These are the only logging after the first start:
$ vi /var/log/mysql/mysqld.log
2022-09-23T05:13:05.359946Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.26) starting as process 243792
2022-09-23T05:13:05.370217Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-23T05:13:05.561488Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-23T05:13:05.748196Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-09-23T05:13:05.748300Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-09-23T05:13:05.749569Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-09-23T05:13:05.749714Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-09-23T05:13:05.766115Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/lib/mysql/mysqlx.sock
2022-09-23T05:13:05.766181Z 0 [System] [MY-010931] [Server] /usr/libexec/mysqld: ready for connections. Version: '8.0.26' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution.
Tried the below as well and I get the same error:
$ sudo mysql -u root -p'p#sSw0rd' -e "CREATE DATABASE ${MAINDB} /*\!40100 DEFAULT CHARACTER SET utf8 */;"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I also tried resetting the password but same error:
$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Access denied for user 'root'#'localhost' (using password: YES)
Can you please suggest?
The issue was due to yum remove mysql-server was not clearing all files and I had to manually delete the folder rm -rf /var/lib/mysql after which a fresh installation helped me log in without password.

"ERROR! MySQL server PID file could not be found!", yet a mysqld process is running on port 3306?

I notice that a mysqld process is running on port 3306:
$ sudo lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 63026 _mysql 19u IPv6 0x67fbb37dac8af9c7 0t0 TCP *:mysql (LISTEN)
I would like to stop this process. However, if I try mysql.server stop, I get the following error:
$ mysql.server stop
ERROR! MySQL server PID file could not be found!
I'm on MacOS, by the way. Using sudo, I'm able to find a .pid file:
$ pwd
/usr/local/mysql
$ sudo find . -name '*pid'
./data/mysqld.local.pid
However, I'm not sure whether it's the one expected by the mysql.server stop command.
The problem I'm ultimately trying to solve is that when I try the mysql command, I get the following error:
$ mysql
ERROR 1045 (28000): Access denied for user 'kurtpeek'#'localhost' (using password: NO)
I'm trying to follow the password reset instructions at https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html, but I can't seem to get past the first step, which is to stop the MySQL server. Any help would be much appreciated.
I found a high-level explanation of this problem at https://apple.stackexchange.com/questions/255671/error-mysql-server-pid-file-could-not-be-found. The server has to be stopped using the MySQL Preferences Pane:
Now the sudo lsof -i :3306 command doesn't show any processes running.

Mysql port already in use

180718 12:43:04 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 10048: Only one usage of each socket address (protocol/network address/port) is normally permitted.
180718 12:43:04 [ERROR] Do you already have another mysqld server running on port: 3306 ?
180718 12:43:04 [ERROR] Aborting
is there any solution for it? Mysql is running on windows based server.
Please give the best solution..
Either a second instance of MySQL or another service is running on port 3306.
You can either stop the service which is running on port 3306 by
getting the process id of that service:
netstat -a -n -o | find "3306"
and then killing that process (e.g. for process id 1234):
taskkill /pid 1234 /f
or run MySQL on a different port.
I had also faced the problem. I stopped the "docker desktop" app(you have to stop from the app if you stop it from the task manager then it will restart automatically).it works for me.
I had a similar problem, I solved it by executing the command to get the PID using the same port:
netstat -a -n -o | find "3306"
After you get the PID, go to Task manager > Services and right click on the service with the same PID, and press stop.
The issue is because mysql workbench uses port:3306 when you try to connect it through PhP platform and the port can only be used by one app so xampp is deprived of it, the reason it's aborting.

Mysql with docker: Can't connect to local MySQL server through socket

I cannot use MySQL anymore in my Docker container:
root#mysql-container:/# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
mysqld is running:
root#mysql-spirit-ssl:/etc/mysql/conf.d# /etc/init.d/mysql start
[info] A MySQL Server is already started.
Trying to stop mysqld timed out:
root#mysql-container:/# /etc/init.d/mysql stop
............................................................[info] Attempt to shutdown MySQL Community Server 5.7.17 timed out.
So I tried to start using the mysqladmin way:
root#mysql-container:/# /usr/bin/mysqladmin --port=8889 -u root shutdown
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)'
So I checked that MySQL daemon is running:
root#mysql-container:/# ps -eax
PID TTY STAT TIME COMMAND
1 ? Ssl 0:01 mysqld
And that socket exists:
root#mysql-container:/# ls -l /var/run/mysqld/mysqld.sock
-rwxrwxrwx. 1 mysql mysql 0 Jan 4 10:12 /var/run/mysqld/mysqld.sock
I already tried to:
restart my Docker container
comment bind address in my.cnf and restart my Docker container
kill mysqld process => does not work, process is still listed by ps -eax
recreate my Docker container
restart Docker
restart the server
delete pid and sock files, and /etc/init.d/mysql start
Result of cat /var/log/mysql/error.log:
2018-02-27T15:27:35.966028Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2018-02-27T15:27:35.966061Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
However I cannot kill that mysqld process, either with pkill mysqld, kill -9 1 or initctl --system stop mysql.
Could this be related to Docker?
Remark: The MySQL daemon could not be killed because it was owned by Docker user systemd+ and it was the entry point of the container. Indeed mysqld was process with PID 1. This means that MySQL daemon could be restarted by simply restarting the Docker container, and that MySQL configuration could be modified in between.
I noticed in MySQL logs tail -f /var/log/mysql/error.log that a data recovery was triggered on daemon start due to an anomaly detected during internal log scan: the database was not closed properly. However the recovery could not repair the data and an intentional crash was performed. As a consequence, the container was restarted and so on. This infinite loop prevented mysqld to start and the socket to be used by the client mysql.
1) This configuration of /etc/mysql/conf.d/my.cnf enabled to skip the recovery:
[mysqld]
innodb_force_recovery=4
and to use mysql client with socket to dump important schemas and/or delete corrupted schemas.
Do not forget to remove this line from my.cnf after you're done!
2) Perfoming a mysql upgrade and repair could also have been beneficial:
docker exec -it mysql-container mysql_upgrade -u root -p --force
mysqlcheck -u root -p --auto-repair --check --all-databases
Restarting the Docker container is necessary after this step.
3) Also, deleting MySQL internal logs (that were scanned and triggered the recovery) was necessary:
cd /var/lib/mysql/mysql/
rm ibdata1 ib_logfile0 ib_logfile1
Now I can use MySQL again, from inside and outside the container.

OS X Mavericks: mysql socket defined in my.cnf, but not getting created

I'm trying to install mysql5 (the latest from Oracle, via .dmg) on OS X Mavericks. My /opt/local/my.cnf looks like this:
[client]
socket=/tmp/mysql.sock
[mysqld]
socket=/tmp/mysql.sock
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
When I try to connect, I get the following:
$ mysql5 -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
And there is no /tmp/mysql.sock file created.
Here's my /tmp dir:
$ ls -l /tmp
lrwxr-xr-x# 1 root wheel 11 Oct 24 08:31 /tmp -> private/tmp
I've also tried forcing the socket from the command line:
$ time sudo mysqld_safe5 --socket=/tmp/mysql.sock
Password:
131221 07:26:02 mysqld_safe Logging to '/opt/local/var/db/mysql5/Macintosh.local.err'.
131221 07:26:02 mysqld_safe Starting mysqld daemon with databases from /opt/local/var/db/mysql5
131221 07:17:26 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
I know it's reading the conf file because if I remove it, I get a different socket location when I attempt to connect:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)
But again, no luck. What do I need to do to get that socket created?
Change your /tmp folder to have permission for MySQL user. (chown mysql:mysql /tmp or chmod 777 /tmp would resolve your issue.)
Try using dtrace to see if mysqld is actually opening a socket, and if so, where. You'll also be able to tell what config files are being read by the server, although that doesn't seem to be the issue since passing --socket=... doesn't work.
I'm used to strace on Linux but recently started using dtrace at work. Here's a pretty simple example of how to trace open(2) calls, which you could modify to trace socket creation, or just all syscalls: https://github.com/tsibley/dtrace-scripts/blob/master/trace-open.d