Hive error: 'Can't connect to local MySQL server through socket - mysql

I installed MySQL Server in CentOS 7:
[root#master1 ~]# rpm -qa | grep mysql
mysql-community-release-el7-5.noarch
mysql-community-server-5.6.39-2.el7.x86_64
mysql-community-common-5.6.39-2.el7.x86_64
mysql-community-client-5.6.39-2.el7.x86_64
mysql-community-libs-5.6.39-2.el7.x86_64
Now I need to execute the following commands:
mysql -u root -p welcome123
CREATE USER 'hive'#'localhost' IDENTIFIED BY 'hivepwd';
However, I get the following error:
[root#master1 ~]# mysql -u root -p welcome123
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
I read the recommendations that it's necessary to check my.cnf but I cannot find this file:
[root#master1 ~]# vi /etc/mysql/my.cnf
[root#master1 ~]# cd /etc/mysql/
-bash: cd: /etc/mysql/: No such file or directory
Finally, I tried to reset the password:
[root#master1 ~]# mysqladmin password newpassword
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
I also tried /usr/bin/mysql_secure_installation. It asks me to enter a root password. So, I generated the password, but it's not accepted and provides the above-shown error.
grep 'A temporary password is generated for root#localhost' /var/log/mysqld.log |tail -1
P.S.
I think that MySQL Server is not actually running:
[root#master1 ~]# ps -ef | grep mysql
root 17964 1 0 17:12 ? 00:00:00 /bin/bash /usr/bin/mysql-systemd-start post
root 20359 14673 0 17:17 pts/0 00:00:00 /usr/bin/perl /usr/bin/mysql_secure_installation
root 21799 14673 0 17:21 pts/0 00:00:00 grep --color=auto mysql
Then I re-install it just in case:
[root#master1 ~]# yum install -y mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.uv.es
* extras: mirror.uv.es
* updates: mirror.uv.es
Package mysql-community-server-5.6.39-2.el7.x86_64 already installed and latest version
Nothing to do
When I want to start the service, it lasts forever:
[root#master1 ~]# systemctl start mysqld.service

Related

Debian 10 MariaDB 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

Good evening Community,
I am in despair because I cannot install MariaDB on Debian10. There are similar Stackoverflow questions but none of them helped to solve my problem.
What I've tried:
$ sudo apt update
$ sudo apt install mariadb-server
So far no errors.
$ sudo mysql_secure_installation
Leads to:
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
systemmd errors
Searching for the file called "mysqld.sock" doesn't deliver results.
$ cd /etc/init.d/
$ mysqld_safe
$ sudo find / -type s | grep mysqld.sock
Doesn't deliver any results. It appears that no mysqld.sock file has been created.
Stackoverflow: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Can anybody please help me with this problem?
Thanks,
milli727
systemctl stop mysql
systemctl stop mariadb
chkconfig --del mysql
systemctl disable mysql
systemctl disable mariadb
systemctl enable mariadb.service
systemctl start mariadb.service

Reset the root password in mysql in Ubuntu 18.04 OS

ok here's the thing I tried installing MySQL-server and it did install perfectly no problem there.
later I had had to format my system and then when I tried to install it, it did install but it did not prompt for the root password. when I later tried to reset the root password here's the problem I get
user#user:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
user#user:~$ sudo mysqld --skip-grant-tables &
[3] 13831
user#user:~$ mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[3] Exit 1 sudo mysqld --skip-grant-tables
I tried resolving the 2002 error but I am unable to do so. any help will be appreciated.
from what I understand I should not get the 2002 error to proceed further
The error is probably due to error in installation. Try the following:
Ensure that my MySQL service is running by executing the following command in the terminal:
$ sudo service mysql start
Verify the state of the process:
$ ps -A|grep mysql
$ ps -A|grep mysqld
Then kill the process with the following command:
$ sudo pkill mysql
$ sudo pkill mysqld
Finally restart the service:
$ sudo service mysql restart
And run the following command:
$ mysql -u root -p
Step#1: Run this command:
sudo mysql_secure_installation
Step#2: press n
Step#3: input your password.
Step#4: press y for until it says All done!
or follow this video tutorial
Also to change the password use this command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';

MySQL won't start in XAMPP Manager-osx

My XAMPP mysql server is working fine
then I download the separate mysql from oracle and installed it. It is running fine but after some days I cant start it as :> mysql -u root
and in xampp mysql server it is also not working it shows stopped always.
I am providing all the commands that I tried from google as well as StackOverflow
and also I am providing all results of all commands.
Please refer commands before answering.
Number indicates ways that I tried.
1.> `mysql -u root -p`
2.> `mysql -u root`
3.> `sudo su`
3.1.> `ps aux | grep mysql`
3.2.> `kill -9 8306`
4.> `sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start`
5.> `sudo killall mysqld`
6.> Changing content of file as: `innodb_force_recovery = 1` in
`/Applications/XAMPP/xamppfiles/etc/my.cnf`
7.> Changing content of file as: read only permission in
`/Applications/XAMPP/xamppfiles/etc/my.cnf`
8.> Port changed from 3306 to 3307 3308 but nothing is happened
9.> Activity manager : mysql service is. not listed
10.> Reinstalled XAMPP
I followed this 10 ways so please dont answer on this 10 ways
Result of commands :
<.1.
Pratiks-MacBook-Pro:~ pratik$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")
<.2.
Pratiks-MacBook-Pro:~ pratik$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")
<.3.
Pratiks-MacBook-Pro:~ pratik$ sudo su
Password:
sh-3.2# ps aux | grep mysql
root 8306 0.0 0.0 4258468 180 s000 U+ 11:35AM 0:00.00 grep mysql
sh-3.2# kill -9 8306
sh: kill: (8306) - No such process
sh-3.2#
<.4.
Pratiks-MacBook-Pro:~ pratik$ sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
Starting MySQL
.2018-03-13 11:44:29 8513 mysqld_safe Logging to '/Applications/XAMPP/xamppfiles/var/mysql/Pratiks-MacBook-Pro.local.err'.
2018-03-13 11:44:29 8513 mysqld_safe Starting mysqld daemon with databases from /Applications/XAMPP/xamppfiles/var/mysql
ERROR!
<.5.
Pratiks-MacBook-Pro:~ pratik$ sudo killall mysqld
No matching processes were found

Ubuntu: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I have a Ubuntu 14.04. server with LAMP installed where an Owncloud is running. I tried to install paperwork which didn't work out but thats not the problem.
After restarting my server I tried to access my owncloud again but I am facing an internal server error. See following picture.
Owncloud error
I looked in the log /var/log/apache2/error.log and theres following phrase:
Lost connection to MySQL server during query' in ...
I tried to restart the mysql service but this error appears:
stop: Unknown instance:
start: Job failed to start
Then I tried to login to mysql with mysql -u root -p and follorwing error appears:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I've looked for the sockets on the machine with find / -type s and the socket was there: /run/mysqld/ .
I created a symbolic link and pasted it to /var/run/mysqld/mysqld.sock
Unfortnutely nothing worked. After restarting again I can't find the socket anymore the output of find / -type s is:
/dev/log
/run/php5-fpm.sock
/run/udev/control
find: `/proc/977/task/977/fd/5': No such file or directory
find: `/proc/977/task/977/fdinfo/5': No such file or directory
find: `/proc/977/fd/5': No such file or directory
find: `/proc/977/fdinfo/5': No such file or directory
Update
I've reinstalled the server so problem is over :D
If you install lampp server, run mysql first
sudo /opt/lampp/lampp startmysql
Then make "mysqld" directory in /var/run
cd /var/run
sudo mkdir mysqld
Link your mysql from lampp to /var/run/mysqld
sudo ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock
run mysql -u root -p . hope may help you
If you install LAMPP server, run MySQL first
sudo /opt/lampp/lampp startmysql
Then make "mysqld" directory in /var/run
cd /var/run
sudo mkdir mysqld
Link your mysql from lampp to /var/run/mysqld
sudo ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock
run MySQL
mysql -u root -p .
If MySQL fails with «mysql» not found, install:
sudo apt install mysql-client-core-5.7
sudo apt install mariadb-client-core-10.1
There is any issues with the mysql services. Please try to restart mysql services and check the mysql error logs for more information

Mysql can't connect to local server through socket on Amazon EC2

I opened my application (in Rails) on Amazon EC2 and got an error - thus I checked the logs and there is following:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
10 hours ago was everything working yet. What's the problem? A lot of traffic?
The app is running on Micro Instance.
How to fix this issue and how to avoid it in the future?
Thank you very much
EDIT:
sudo find / -type s
---
/tmp/.sock
/dev/log
/var/lib/apt-xapian-index/update-socket
/run/mysqld/mysqld.sock
/run/acpid.socket
/run/dbus/system_bus_socket
/run/udev/control
find: `/proc/4739/task/4739/fd/5': No such file or directory
find: `/proc/4739/task/4739/fdinfo/5': No such file or directory
find: `/proc/4739/fd/5': No such file or directory
find: `/proc/4739/fdinfo/5': No such file or directory
In my case, the server had apparently restarted at some point, and mysql was not started when it did. I simply typed the command to start and it worked:
sudo service mysqld start
locate your locate my.cnf file see there for line as socket = ../../mysql.sock
you need to replace the path with your path as
socket = /run/mysqld/mysqld.sock
if the path matches let me know
Cross posting my response from here.
I had this same problem on an ec2 instance. These instructions worked perfectly for me:
Redhat Enterprise Linux - RHEL 5 / 6 MySQL installation
Type the following command as root user:
yum install mysql-server mysql
Redhat Enterprise Linux - RHEL 4/3 MySQL installation
Type the following command as root user:
up2date mysql-server mysql
Start MySQL Service
To start the mysql server type the following command:
chkconfig mysqld on
/etc/init.d/mysqld start
Setup the mysql root password
Type the following command to setup a password for root user:
mysqladmin -u root password NEWPASSWORD
Test the mysql connectivity
Type the following command to connect to MySQL server:
$ mysql -u root -p
In my case I used command below:
project_folder > mysql.server start
After system return SUCCESS message it worked OK.
mysql-server is not installed by default on the Amazon Linux AMI. Use these commands to install it:
$ sudo yum install mysql-server
$ sudo chkconfig mysqld on
$ sudo /etc/init.d/mysqld start
$ mysqladmin -u root password NEWPASSWORD
$ mysql -u root -p
To solve this error first find your socket file, run the following commands in terminal
mysqladmin variables | grep socket
For me, this gives:
| socket | /var/run/mysqld/mysqld.sock
Then, add a line to your Rails application: config/database.yml:
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /var/run/mysqld/mysqld.sock
This will solve this problem.