Resetting mysql password results: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) - mysql

I keep getting the error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)
When trying to connect to MySQL via terminal.
I've done both tutorials:
The official one:
https://help.ubuntu.com/community/MysqlPasswordReset
and a less official one:
https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts
Creating the file /var/run/mysqld/mysqld.sock actually works after giving it permissions chown -R mysql /var/run/mysqld chown -R mysql /var/run/mysqld/mysqld.sock and then I can log in to mysql in the terminal and change my main user and root users the password.
After running sudo /etc/init.d/mysql start or sudo /etc/init.d/mysql restart I again - cannot connect to mysql using my user names and passwords.
service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-05-07 12:00:51 IDT; 43s ago
Process: 11057 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 11042 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 11056 (mysqld)
Tasks: 13 (limit: 4915)
Memory: 103.3M
CPU: 464ms
CGroup: /system.slice/mysql.service
└─11056 /usr/sbin/mysqld
May 07 12:00:20 asd systemd[1]: Starting MySQL Community Server...
May 07 12:00:51 asd systemd[1]: Started MySQL Community Server.
Following this post:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
Restarting mysql didn't work as mentioning at the begging of the post when running sudo /etc/init.d/mysql start again results:
sudo /etc/init.d/mysql start
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
sh: 0: getcwd() failed: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[....] Starting mysql (via systemctl): mysql.servicejob-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[ ok job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
.
sudo service mysql start
sh: 0: getcwd() failed: No such file or directory
completely reinstalling MySQL isn't acceptable.
One of the commenters said:
The client should be set consistent with server setting.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
which is weird because in my directory /var/run/mysqld/ the mysqld.sock file gets somehow deleted and don't have anything that looks like this in my /etc/mysql/my.cnf file:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
#bind-address = 127.0.0.1
How do i stable my MySQL login properly?
Why is this happening?
Running:
Distributor ID: Ubuntu
Description: Ubuntu 17.10
Release: 17.10
Codename: artful

In termux while using PHP v8.1.3 and MariaDB 10.6.4 l faced the same issue and l tried : telnet 127.0.0.1 3306 and l received the following response:
telnet: Unable to connect to remote host: Connection refused
And l knew that MySQL sever was not running and went further to run the following:
$PREFIX/etc/init.d/mysql stop
And received the following response:
ERROR! MariaDB server process #9102 is not running!
And l knew the problem is l haven't started the MySQL service which you may start as follows:
$PREFIX/etc/init.d/mysql start
In termux
Or
sudo /etc/init.d/mysql start
In Ubuntu
The response from termux is
Starting MariaDB.
220318 11:44:24 mysqld_safe Logging to '/data/data/com.termux/files/usr/var/lib/mysql/localhost.err'.
220318 11:44:25 mysqld_safe Starting mariadbd daemon with databases from /data/data/com.termux/files/usr/var/lib/mysql.
SUCCESS!
Good lucky!!!!

Are you still facing this issue? probably not but something similar happened to me and I realized that while the query was running OK, it was not affecting any rows...I modified the query to match only 'localhost' and that worked:
UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';

Related

Unable to start the MySQL docker container on WSL2

I am currently using a docker container to run MySQL on WSL2 and I am facing an issue while running this container. I checked the docker logs and got the following issue -
Docker started and then immediately exited with the code (1) and then I checked the docker logs and it was giving the error as -
[ERROR] 'Setup of socket: '/var/run/mysqld/mysqlx.sock' failed, another process with PID is using UNIX socket file'
[ERROR] Another process with pid is using unix socket file.
[ERROR] Unable to setup unix socket lock file.
[ERROR] Aborting
How can I resolve this error and start my container again?
Following are the steps that I tried to resolve this issue -
Firsly, stop your docker service by using following command - "sudo service docker stop"
Now,get into the docker folder in my Linux system using the following path - /var/lib/docker.
Then within the docker folder you need to get into the volumes folder. This folder contains the volumes of all your containers (memory of each container) - cd /volumes
After getting into volumes do 'sudo ls' you will find multiple folders with hash names. These folders are volumes of your containers. Each folder is named after its hash (You need to inspect your docker container and get the hash of your container volume. For this, you need to do the following steps -
Run command "docker inspect 'your container ID' ".
Now you will get a JSON file. It is the config file of your docker container.
Seach for Mounts key within this JSON file. In Mounts, you will get the Name(hash) of your volume. (You will also get the path of your volume within the Mounts. Within Mounts "Name" key is your volume name and "Source" is the path where your volume is located.)).
Once you get the name of your volume you can go within your volume folder and within this folder you will find "_data" folder. Get into this folder.
Finally within "_data" folder use sudo ls command and you will find a folder with the name mysql.sock.lock. Remove this folder By "rm -f mysql.sock.lock".
Now restart your docker service and then start your docker container. It will start working.
Note- Use sudo in each command while you are in the docker container folder.

ERROR! The server quit without updating PID file (/usr/local/var/mysql/Bridge.local.pid)

I was not able to run mysql so i deleted it and reinstalled it using home brew .Now when i run the mysql.server start command i get the following error
ERROR! The server quit without updating PID file (/usr/local/var/mysql/Bridge.local.pid).
Here are the contents of my my.conf file in usr/local/Cellar/mysql/5.7.10/mysql-test/include/default_my.cnf where homebrew has installed mysql
# Use default setting for mysqld processes
!include default_mysqld.cnf
!include default_client.cnf
[mysqld.1]
# Run the master.sh script before starting this process
#!run-master-sh
log-bin= master-bin
# Run tests with the performance schema instrumentation
loose-enable-performance-schema
[mysqlbinlog]
disable-force-if-open
[ENV]
MASTER_MYPORT= #mysqld.1.port
MASTER_MYSOCK= #mysqld.1.socket
~
Maybe mysql does not have permission to the folder where the pid file is located in.
Solution working for my case:
Check your error log at /usr/local/var/mysql/Bridge.local.err
If there is something like this in the log: ...[Note] Unable to delete pid file: Permission denied..., which means mysql does not have the permission to
your mysql folder
Use the following command in terminal to grant the permission: sudo chown -R mysql /usr/local/var/mysql/

mysqld: Can't change dir to data. Server doesn't start

I installed a MySQL server with installer and it started. After reboot I tried to start it again and get the error:
D:\Program Files\MySQL\MySQL Server 5.7\bin>mysqld -u root -p
mysqld: Can't change dir to 'D:\Program Files\MySQL\MySQL Server 5.7\data\' (Errcode: 2 - No such file or directory)
2015-11-17T08:30:18.822962Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-17T08:30:18.822962Z 0 [Warning] Insecure configuration for --secure- file -priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2015-11-17T08:30:18.822962Z 0 [Note] mysqld (mysqld 5.7.9) starting as process 1108 ...
2015-11-17T08:30:18.838586Z 0 [Warning] Can't create test file D:\Program Files\MySQL\MySQL Server 5.7\data\DESKTOP-RNBR3E8.lower-test
2015-11-17T08:30:18.838586Z 0 [Warning] Can't create test file D:\Program Files\MySQL\MySQL Server 5.7\data\DESKTOP-RNBR3E8.lower-test
2015-11-17T08:30:18.838586Z 0 [ERROR] failed to set datadir to D:\Program Files\MySQL\MySQL Server 5.7\data\
2015-11-17T08:30:18.838586Z 0 [ERROR] Aborting
2015-11-17T08:30:18.838586Z 0 [Note] Binlog end
2015-11-17T08:30:18.838586Z 0 [Note] mysqld: Shutdown complete
I tried to reinstall MySQL.
UPDATE:
When I run mysqld -u root -p as administrator, nothing happens.
I have met same problem. In my case I had no ..\data dir in my C:\mysql\ so I just executed mysqld --initialize command from c:\mysql\bin\ directory and I got the data directory in c:\mysql\data. Afterwards I could use mysqld.exe --console command to test the server startup.
Since you used the Windows installer, everything is set up for you to run MySQL 5.7 as a Windows service, which is a great option in most cases.
Instead of running mysqld.exe from the command line,
Win + R
Run services.msc
Right-click on MySQL57
Start the service.
In my case, I had installed the data directory to a different location. So the data directory really wasn't in the default location. Therefore, when I ran the mysqld command from the command prompt, I had to specify the data directory manually:
mysqld --datadir=D:/MySQLData/Data
Here's the documentation for mysqld command-line arguments.
First run
mysqld -u root --initialize-insecure
It will create data folder with root as user without password. Then run
mysqld.exe -u root --console
What I did (Windows 10) for a new installation:
Start cmd in admin mode (run as administrator by hitting windows key, typing cmd, right clicking on it and selecting "Run as Administrator"
Change into "MySQL Server X.Y" directory (for me the full path is C:\Program Files\MySQL\MySQL Server 5.7")
using notepad create a my.ini with a mysqld section that points at your data directory
[mysqld]
datadir="X:\Your Directory Path and Name"
created the directory identified in my.ini above.
change into bin Directory under server directory and execute:
mysqld --initialize
Once complete, started the service and it came up fine.
Check that the director exists.
If it exists make sure mysql has access rights on it (read/write). Can be a good idea to run MySQL as a system process, but not mandatory.
If this is stil not working try having the following notation with double slashes: C:\WebSerer\MySQL\data or C:/WebServer/MySQL/data
If you are having this issue and can't find the MySQL service either, just launch "MySQL Installer" from the Start menu (or download it), then choose "Reconfigure" on MySQL Server. Follow the steps to set a root user password and then the service will be created and started automatically (and set to auto-start on boot).
In mysql 8.0.13 zip package initializing.
Verify that data folder is empty.
Under the mysql bin path run
mysqld.exe --initialize-insecure
Add to my.ini native mysql
[mysqld]
default_authentication_plugin=mysql_native_password
When I encountered this same error, I noticed MySQL Configuration file in "C:\Program Files\MySQL\MySQL Server X.Y\" has changed to my-default.ini
I solved it by
Copy my.ini from "C:\ProgramData\MySQL\MySQL Server X.Y\my.ini"
Paste it in "C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
Restart MySQL Server from services.msc
In the .ini file, their is part that reads:
# On Windows you should keep this file in the installation directory
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option
# "--defaults-file".
Check your real my.ini file location and set --defaults-file="location" with this command
mysql --defaults-file="C:\MYSQL\my.ini" -u root -p
This solution is permanently for your cmd Screen.
remove all files in "{path-to-mysql}\data" directory and run:
mysqld --initialize-insecure --basedir={path-to-mysql}\mysql --datadir={path-to-mysql}\data --console
I don't know if it's your problem but try this...
For me, the version of my.ini which is created under "ProgramData\MySQL\MySQL Server [version]" wasn't read. I had to move it to "Program Files\MySQL\MySQL Server [version]".
RTS.
If you installed MySQL Server using the Windows installer and as a Window's service, then you can start MySQL Server using PowerShell and experience the convenience of not leaving the command line.
Open PowerShell and run the following command:
Get-Service *sql*
A list of MySQL services will be retrieved and displayed. Choose the one that you want and run the following command while replacing service-name with the actual service name:
Start-Service -Name service-name
Done. You can check that the service is running by running the command Get-Service *sql* again and checking the status of the service.
mariofertc completely solved this for me here are his steps:
Verify mysql's data directory is empty (before you delete it though, save the err file for your records).
Under the mysql bin path run:
mysqld.exe --initialize-insecure
add to my.ini (mysql's configuration file) the following:
[mysqld]
default_authentication_plugin=mysql_native_password
Then check services (via task manager) to make sure MySql is running, if not - right click MySql and start it.
I'll also note, if you don't have your mysql configuration file in the mysql bin and can't find it via the windows search, you will want to look for it in C:\Program Data\Mysql\ Note that it might be a different name other than my.ini, like a template, as Heesu mentions here: Can't find my.ini (mysql 5.7)
Just find the template that matches the version of your mysql via the command mysql --version
This solution uses the windows mysql installer.
I have tried every other way mentioned here and other related posts, but it did not solve my problem, the service just wont start, but the below approach with the mysql-installer did.
If you still have your installer or atleast remember the version then follow below steps:
Start your windows mysql installer. For me it was "mysql-installer-community-8.0.20.0"
Then remove/uninstall the SQL Server and remove all configurations
Manually delete the SQL Server folder from "C:\Program Files\MySQL\MySQL Server 8.0."
Start your mysql installer again and install the SQL Server again
You can check from the window's services that the MySqL Server has started.
Hope it helps someone.
Check for missing folders that are required by the server, in my case it was UPLOADS folder in programData which was deleted by empty folder cleaner utility that I used earlier.
How did I find out:
run the server config file my.ini(in my case it was in programData) as the defaults-file param for mysqld (don't forget to use --console option to view error log on screen)
'mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --console'
Error:
mysqld: Can't read dir of 'C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\' (OS errno 2 - No such file or directory)
Solution:
Once I manually created the Uploads folder the server started successfully.
In my case, I'm MySQL5.6, install by workbrench install tools in Win10 pro.
there are two configuration file need to modify,
only edit the line: datadir=E:\MySQL
stop MySQL56 service using services.msc
edit my.ini under C:\ProgramData\MySQL\MySQL Server 5.6
edit my-default.ini under C:\Program Files\MySQL\MySQL Server 5.6
copy C:\ProgramData\MySQL\MySQL Server 5.6*.* to E:\MySQL
start MySQL56 service using services.msc
test: create database 'testdb';
It's successed if found testdb folder exist in E:\MySQL.

MySQL not starting up after added log-bin - Master Replication

I trying to set up master replication server. When I try to start/restart the server after added log-bin directory as following in my.cnf,
log-bin = /var/log/mysql/mysql-bin.log
the server is not starting up.
MySQL status
mysqld.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysqld.service; enabled)
Active: inactive (dead) since Mon, 13 Jul 2015 17:46:47 +0800; 1s ago
Process: 14145 ExecStart=/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/mysqld.service
But after I changed the log-bin as following (without folder path)
log-bin = mysql-bin.log
the server is running successfully.
MySQL status
mysqld.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysqld.service; enabled)
Active: active (running) since Mon, 13 Jul 2015 17:47:43 +0800; 2s ago
Main PID: 15272 (mysqld_safe)
CGroup: name=systemd:/system/mysqld.service
├ 15272 /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysq...
└ 15615 /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/...
Update
From mysqld.log :
/var/log/mysql/mysql-bin.index' not found (Errcode: 2)
But my mysql-bin.index by default at
/var/lib/mysql/mysql-bin.index
Could anyone please help me out as I just start to learn master-slave replication? Do I need to create a folder name mysql and change the permission to mysql and put in log directory or how I can make sure it locates my mysql-bin.index file correctly?
Finally I have found the solution. Not sure whether I did it in a right way.
After searched about (Errcode: 2), found that it is indicate that the file or directory does not exist. So I have created the folder named as mysql and added in log directory (Logged in as root user). When I try to restart the server, it gives me another error:
/var/log/mysql/mysql-bin.index' not found (Errcode: 13)
Errcode: 13 indicates permission denied. So I have change the ownership from root to mysql :
chown -R mysql:mysql /var/log/mysql
I restart the server and it runs successfully.
If there is an error in path access related to data and logs of mysql it will call the default /var/lib/mysql and /var/log/mysql. To ovveride mysql log file path do the following.
create new path
make the path with ownership of mysql user
example - sudo shown -R mysql:mysql /mnt/mysql/logs
pass the path to apparmor to read this directory.
file location - /etc/apparmor.d/usr.sbin.mysqld
content
# Allow log file access
/mnt/mysql/logs/ r,
/mnt/mysql/logs/** rw,
Note: if apparmor has not correct path then it will give issue of permission that confuses with simple chown and chmod

Can't create/write to file '/var/lib/mysql/aria_log_control'

Something is wrong. I stopped MaridaDB, moved /var/lib/mysql to a different place, then replaced the old mysql with a softlink
cd /var/lib
ln -s /data/mysql .
Then I added
chown -R mysql:mysql mysql
and then I went to /data and did the same (Note: this relocation works fine in regular mysql). But in MariaDB
ERROR] mysqld: Can't create/write to file
'/var/lib/mysql/aria_log_control' (Errcode: 13 "Permission denied")
[ERROR] mysqld: Got error 'Can't create file' when trying to use aria
control file '/var/lib/mysql/aria_log_control' [ERROR] Plugin 'Aria'
init function returned error. [ERROR] Plugin 'Aria' registration as a
STORAGE ENGINE failed.
So what can I do to fix this? I tried setting
chmod 777 /var/lib/mysql/aria_log_control
but to no avail.
In my case the problem was that while directory mysql and files within were owned by user mysql, the path has a directory that lacked x bit for the users that are not in the correct group. In other words, user could not move to the target directory because one of the directories in the path did not allow it.
In My case this happened after a change which required OS restart, turned out that SELINUX was in ENFORCE mode and was not allowing MySQL to access the files, used below command to resolve:
sudo getenforce
sudo setenforce 0