WSL: ERROR 2002 (HY000): Can't connect to local MySQL server through socket...
Hello!
I’m trying to install MySQL on Bash on Ubuntu on Windows. I’m running bash as admin and run sudo apt-get install mysql-server. In the middle of the installation I can find this:
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
runlevel:/var/run/utmp: No such file or directory
invoke-rc.d: policy-rc.d denied execution of stop.
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
runlevel:/var/run/utmp: No such file or directory
invoke-rc.d: policy-rc.d denied execution of start.
And when I start mysql, I get this:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Are this sockets not supported yet or am I doing something wrong? Thanks!
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 17
- Comments: 34 (2 by maintainers)
I had this issue as well. MySQL is installed but could not be run automatically. You can start MySQL with this command:
sudo /etc/init.d/mysql start@danwhitston @Kubitomakita
I found a temporary solution. Open
/etc/mysql/mysqld.conf.d/mysqld.confand add the following to the bottom of the fileThis will force the mysql client to use TCP clients instead of unix sockets. That way you can connect to your localhost database running on Windows.
If you don’t need it as default, append
--protocol=tcpto the mysql command.Same thing here
Hi
I have the same issue with Mysql.
With this
Not exactly the same error with this
i try this
Build 15063.138
Need some help please… thank you! 😃
For future visitors, I fixed my problem with MySQL version 8 installation using this comment:
I checked the error log in /var/log/mysql/error.log and realized there was a problem with this description “Linux Native AIO interface is not supported on this platform.” so I Googled it and bumped into the [very helpful] above comment. Hope this also works for you!
Just dropping something related here:
Say you run
mysqldunder Windows (Win64). And you want to connect from WSL. It will try to connect to through a socket file (named pipe), but that won’t work. Here’s how to do that:You of course need to add all your own options (e.g
-u <name> -p).You can set this as the default behaviour.
sudo vim /etc/mysql/mariadb.conf.d/50-client.cnf, under[client]comment out the socket line with a#, add a line that readsprotocol = TCP(to exitvim, press [ESC] and type:wq). The path of this file might be different with an actual Oracle MySQL install, instead of MariaDB.Still trying to figure out how to do this from the various mysql drivers in PHP. The recommended way to connect to
127.0.0.1to circumvent thelocalhostheuristics doesn’t work with whatever artisan/laravel uses.https://stackoverflow.com/a/55844865/273668
How is this said to be fixed? I’m having the same issue.
@aderchox’s answer helped me, I’m on windows 10 with wsl 2 running ubuntu 18.04. in my case the problem was in the installation of MySQL using the current apt .deb package, it proceeded with the installation but never added the mysql.sock file at /var/bin/mysql/ neither /var/lib/mysql/ . Just adding to @aderchox’s answer, the link of mysql-apt-config_0.8.15-1_all.deb is here, and if there is a problem like “MySQL 8.x could not start” or something like that, just kill the process and start again the server
@mbeijen thanks for the information. It worked out with
--protocol=tcpbut I had to rewrite some lines of the CLI until I got to the point where some parts weren’t editable. 😃Still looking for some better solution.
I have solved this issue from the below answere. Yaho0o0o. https://stackoverflow.com/questions/64883580/wsl-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld/66949451#66949451
@hacdias - Thanks for reporting this. Is manually starting MySQL using
mysql startworking for you? Currently, in WSL we do not start the ‘upstart’ service and so you are seeing the failure. We are looking into supporting some of these services\deamons.@aderchox Thank you, after reseting debian to remove the old mysql8 packages your solution worked
I found that I needed to stop mysql service running in windows before I could run mysql in WSL.
I already have another mysqld server running on port: 3306
See this answer on S/O: https://stackoverflow.com/questions/44247342/starting-mysql-on-bash-on-ubuntu-on-windows
@VoLuong - Yes, Xenial is officially supported in the Insider builds. It will be also be officially supported in the Windows
Creators Updaterelease.