Unable to start the mysql server in ubuntu
Asked Answered
I

9

35

After running the command mysql -v in Ubuntu, I am getting the following error:

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

Inglebert answered 14/12, 2016 at 16:33 Comment(0)
K
74

I think this is because you are using client software and not the server.

  • mysql is client
  • mysqld is the server

Try:

sudo service mysqld start

To check that service is running use: ps -ef | grep mysql | grep -v grep.

Uninstalling:

sudo apt-get purge mysql-server
sudo apt-get autoremove
sudo apt-get autoclean

Re-Installing:

sudo apt-get update
sudo apt-get install mysql-server

For all the editors who make edits without any understanding of the subject: Please stop attempting to move this section to the top!

Previous steps did not work, anything else I can try?

You could delete apt.conf.d folder and pull updates again. This is only needed in rare cases. It was much more common back in 2016 when this answer was originally written. Before executing following commands take a backup of entire folder, make a copy of it, or create an archive of it:

### EXECUTING THE FOLLOWING COMMAND CAN CAUSE HARM TO YOUR SYSTEM
### UNDERSTAND WHAT YOU ARE DELETING BEFORE PROCEEDING
sudo rm /etc/apt/apt.conf.d/50unattended-upgrades*
sudo apt-get update
sudo apt-get upgrade
Kurbash answered 14/12, 2016 at 16:35 Comment(11)
I am getting this error Failed to start mysqld.service: Unit mysqld.service not foundInglebert
How did you install it? Did you use sudo apt-get install mysql-server?Kurbash
yes but got something like this: N: Ignoring file '50unattended-upgrades.ucf-old' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension E: Sub-process /usr/bin/dpkg returned an error code (1)Inglebert
It looks like it did not get installed correctly. You will need to delete what is there and reinstall. Uninstalling and removing config by: sudo apt-get purge mysql-server. This is a good step to run Autoclean and autoremove: sudo apt-get autoremove && sudo apt-get autoclean. Not to install run: sudo apt-get update && sudo apt-get install mysql-server. Hope this helps.Kurbash
getting same error again Errors were encountered while processing: mysql-server-5.7 mysql-server N: Ignoring file '50unattended-upgrades.ucf-old' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension E: Sub-process /usr/bin/dpkg returned an error code (1)Inglebert
Backup folder. Remove 50unattended-upgr* and re-run update & install. Updating all packages wouldn't hurt as well. See update to my answer.Kurbash
If you dont want your data to be lost sudo apt-get update sudo apt-get install mysql-server is enoughCaracole
This worked for me, sudo apt-get upgrade triggered a message asking if I wanted to replace the deleted 50unattended-upgrades file with the manufacturer version. This defaults to no, so make sure you enter Y if you want that file to be replaced.Poetize
You should write this line "Backup entire folder before doing this:" above of the answer. because I read this line after uninstalling mysql but thank god I didn't had important database createdCaliph
i tried with restarting mysql service no worked , then reinstall mysql client dependency and reconfigure mysql . and restarted the service again , everything works fine , sounds weird but works ! root case : in my case while trying to remove python ..stupid command removed few dependency also . so had to reinstall thoseWagon
Worked for me. I had MySQL Workbench, but it said that the server wasn't running. It wasn't until I did the server install listed above that I could create schemas/tables etc.Extension
S
6

By default, apt install MariaDB but not mySQL.

sudo apt install default-mysql-server

If you would like to install real mySQL database by apt, follow these steps.

Firstly, we need to remove all preceding mysql installed on the host.

sudo apt-get --purge autoremove "^mysql.*"

Dowload the stable package mysql-apt-config_0.8.15-1_all.deb from

sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb

Install the downloaded release package:

sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb

Refresh your apt package cache to make the new software packages available

sudo apt update

Install MySQL by executing:

sudo apt-get update   
sudo apt-get install mysql-server mysql-client
libmysqlclient-dev

Check mysql status:

sudo service mysql status
Sacking answered 10/2, 2022 at 13:36 Comment(2)
worked for me, you can change sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb for last version from https://dev.mysql.com/downloads/repo/apt/ and just edit version numberSaraisaraiya
Thank's a loooooootttttttt. it work for me, after weeks of searching the solution... Do not forget to change sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb for last version from dev.mysql.com/downloads/repo/apt and just edit version number as @MrezaNemati told.Doubledecker
R
4

Yes, should try reinstall mysql, but use the --reinstall flag to force a package reconfiguration. So the operating system service configuration is not skipped:

sudo apt --reinstall install mysql-server
Refute answered 27/9, 2020 at 16:6 Comment(2)
I guess is just sudo apt reinstall mysql-serverMeyer
this solution does not work. initial error is there.Tsana
S
3

I fixed by "purging" every file related to mysql and reinstalling mysql-server:

sudo apt-get purge mysql-server mysql-client mysql-common
sudo apt-get install mysql-server
Sapodilla answered 2/12, 2021 at 4:51 Comment(0)
D
2

Navigate to /etc/systemd/system/ and do the following

  1. sudo rm -rf mysql.service
  2. sudo rm -rf mysqld.service
Digraph answered 14/10, 2022 at 17:5 Comment(0)
P
2

You can try this command

sudo systemctl start mysql.service

Polestar answered 29/12, 2023 at 5:5 Comment(0)
S
1

Try running

sudo apt-get install mysql-server 

if not installed.

Schulte answered 30/11, 2021 at 4:39 Comment(0)
C
0

I tried this also and more (re-installation etc.)

The answer was : I found query_cache_limit and removed it from the /etc/mysql/my.cnf file.

As soon as I removed it, the error log changed to a query_cache_size one so I removed that one too from my.cnf file. Within seconds, MySQL restarted successfully and I was back in business.

* Query Cache Configuration
query_cache_limit = 1M   
query_cache_size  = 16M 
* Logging and Replication
#
Cerous answered 6/9, 2021 at 21:22 Comment(0)
S
0

I also faced same issue, and i restarted my Ubuntu 20 and mysql worked normally

Sandiesandifer answered 7/6 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.