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

What issue or error are you experiencing?

Hello,
I am using Localwp on my Linux Mint 21.3 Cinnamon. I want to make a backup of the WordPress website I have been working on using Duplicator plugin. When the backup tried to build, I get the below error message posted by Duplicator:

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

Thank you for helping me,
Matei


What steps can be taken to replicate the issue? Feel free to include screenshots, videos, etc

here is the entire Duplicator log report:

********************************************************************************
DUPLICATOR-LITE PACKAGE-LOG: June 7, 2025 10:04 am
NOTICE: Do NOT post to public sites or forums 
********************************************************************************
VERSION:	1.5.12
WORDPRESS:	6.8.1
PHP INFO:	8.1.29 | SAPI: fpm-fcgi
SERVER:		nginx/1.26.1 
PHP TIME LIMIT: (0) no time limit imposed 
PHP MAX MEMORY: 4294967296 (256M default) 
MEMORY STACK: 10MB

********************************************************************************
DATABASE:
********************************************************************************
BUILD MODE:   MYSQLDUMP
MYSQLTIMEOUT: 5000
MYSQLDUMP:    Is Supported
MYSQL DUMP ERROR 2

==================================================================================
DUPLICATOR ERROR
Please try again! If the error persists see the Duplicator 'Help' menu.
---------------------------------------------------------------------------------
MESSAGE:
	Shell mysql dump error. Change SQL Mode to the "PHP Code" in the Duplicator > Settings > Backups.
DETAILS:
	mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when trying to connect
/* Duplicator WordPress Timestamp: 2025-06-07 10:04:33*/
/* DUPLICATOR_MYSQLDUMP_EOF */
TRACE:
	 1. class.pack.database.php : error (608)
	 2. class.pack.database.php : mysqlDump (230)
	 3. class.pack.php : build (1378)
	 4. ctrl.package.php : runZipBuild (89)
	 5. class-wp-hook.php : duplicator_package_build (324)
	 6. class-wp-hook.php : apply_filters (348)
	 7. plugin.php : do_action (517)
	 8. admin-ajax.php : do_action (192)
==================================================================================


==================================================================================
DUPLICATOR ERROR
Please try again! If the error persists see the Duplicator 'Help' menu.
---------------------------------------------------------------------------------
MESSAGE:
	Runtime error in DUP_Database::Build. Shell mysql dump error. Change SQL Mode to the "PHP Code" in the Duplicator > Settings > Backups.
DETAILS:
	Exception: Exception: Shell mysql dump error. Change SQL Mode to the "PHP Code" in the Duplicator > Settings > Backups. in /home/matei/Local Sites/brent/app/public/wp-content/plugins/duplicator/classes/class.logging.php:301
Stack trace:
#0 /home/matei/Local Sites/brent/app/public/wp-content/plugins/duplicator/classes/package/class.pack.database.php(608): DUP_Log::error('Shell mysql dum...', 'mysqldump: Got ...', 1)
#1 /home/matei/Local Sites/brent/app/public/wp-content/plugins/duplicator/classes/package/class.pack.database.php(230): DUP_Database->mysqlDump('/usr/bin/mysqld...')
#2 /home/matei/Local Sites/brent/app/public/wp-content/plugins/duplicator/classes/package/class.pack.php(1378): DUP_Database->build(Object(DUP_Package), 1)
#3 /home/matei/Local Sites/brent/app/public/wp-content/plugins/duplicator/ctrls/ctrl.package.php(89): DUP_Package->runZipBuild()
#4 /home/matei/Local Sites/brent/app/public/wp-includes/class-wp-hook.php(324): duplicator_package_build('')
#5 /home/matei/Local Sites/brent/app/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#6 /home/matei/Local Sites/brent/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#7 /home/matei/Local Sites/brent/app/public/wp-admin/admin-ajax.php(192): do_action('wp_ajax_duplica...')
#8 {main}
TRACE:
	 1. class.pack.database.php : error (259)
	 2. class.pack.php : build (1378)
	 3. ctrl.package.php : runZipBuild (89)
	 4. class-wp-hook.php : duplicator_package_build (324)
	 5. class-wp-hook.php : apply_filters (348)
	 6. plugin.php : do_action (517)
	 7. admin-ajax.php : do_action (192)
==================================================================================

System Details

  • Local Version: Version 9.2.4+6788

  • Operating System (OS) and OS version: Linux Mint 21.3 Cinnamon


Local Logs

Attach your Local Logs here (Help Doc - Retrieving Local’s Log)
local-lightning.log (343.3 KB)


Security Reminder
Local does a pretty good job of scrubbing private info from the logs and the errors it produces, however there’s always the possibility that something private can come through. Because these are public forums, always review the screenshots you are sharing to make sure there isn’t private info like passwords being displayed.

Hi @matei

Have you tried changing your Router Mode?

Router Mode

You might also check if you have any developer applications or security applications that could be interfering.

As a couple of workarounds, you can always use Local’s native export feature to save a zip backup copy of the site. Or copy the Local Site files directly. For another plugin option, WP Migrate Lite is free and can take a full site export and save it as a zip as well.

Hi Nick, Yes, I can only start my website using localhost. The Site Domain does not even load the website. It does not connect at all. Please see message I get when switching to Site Domain.
Thank you

Thanks Nick for the suggested backup options. I guess, on all options, I have to backup the database separately. Am I correct?

We had another Linux Mint user with the same issue here recently in case this is helpful in troubleshooting:

If you need to stay on Localhost would the workaround options help out for now?

Thanks Nick

aa-status gave this output below. But changing unprivileged_port_start=0 seems to have solved the Site Domain issue. I’ll investigate further if needed related to the backup solutions. This was very helpful Nick. Thank you.

$ sudo aa-status
[sudo] password for matei:          
apparmor module is loaded.
39 profiles are loaded.
37 profiles are in enforce mode.
   /usr/bin/evince
   /usr/bin/evince-previewer
   /usr/bin/evince-previewer//sanitized_helper
   /usr/bin/evince-thumbnailer
   /usr/bin/evince//sanitized_helper
   /usr/bin/evince//snap_browsers
   /usr/bin/man
   /usr/bin/redshift
   /usr/lib/NetworkManager/nm-dhcp-client.action
   /usr/lib/NetworkManager/nm-dhcp-helper
   /usr/lib/connman/scripts/dhclient-script
   /usr/lib/cups/backend/cups-pdf
   /usr/lib/lightdm/lightdm-guest-session
   /usr/lib/lightdm/lightdm-guest-session//chromium
   /usr/sbin/cups-browsed
   /usr/sbin/cupsd
   /usr/sbin/cupsd//third_party
   /{,usr/}sbin/dhclient
   libreoffice-senddoc
   libreoffice-soffice//gpg
   libreoffice-xpdfimport
   lsb_release
   man_filter
   man_groff
   nvidia_modprobe
   nvidia_modprobe//kmod
   tcpdump
   ubuntu_pro_apt_news
   ubuntu_pro_esm_cache
   ubuntu_pro_esm_cache//apt_methods
   ubuntu_pro_esm_cache//apt_methods_gpgv
   ubuntu_pro_esm_cache//cloud_id
   ubuntu_pro_esm_cache//dpkg
   ubuntu_pro_esm_cache//ps
   ubuntu_pro_esm_cache//ubuntu_distro_info
   ubuntu_pro_esm_cache_systemctl
   ubuntu_pro_esm_cache_systemd_detect_virt
2 profiles are in complain mode.
   libreoffice-oosplash
   libreoffice-soffice
0 profiles are in kill mode.
0 profiles are in unconfined mode.
2 processes have profiles defined.
2 processes are in enforce mode.
   /usr/sbin/cups-browsed (1428) 
   /usr/sbin/cupsd (1112) 
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.
0 processes are in mixed mode.
0 processes are in kill mode.
1 Like

Glad to hear that @matei! Thank you for following up and letting us know.

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.