ubuntu Can't connect to local MySQL server through socket
时间: 2023-08-26 08:17:32 浏览: 292
回答: 当在Ubuntu下出现"Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"错误时,这通常表示MySQL服务器无法通过指定的socket连接。解决这个问题的方法是按照以下步骤进行操作:
1. 打开终端并使用以下命令编辑MySQL配置文件:sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf [3]
2. 在文件中找到"socket"行,确保其值为"/var/run/mysqld/mysqld.sock",如果不是,请进行相应的更改。
3. 在"mysqld"部分的末尾添加"skip-grant-tables",保存并关闭文件。这将允许您绕过权限验证,以便在修复问题之后重新连接到MySQL服务器。
4. 使用以下命令重新启动MySQL服务:sudo service mysql restart
5. 现在,尝试连接MySQL服务器,应该不再出现该错误信息。
通过按照上述步骤操作,您应该能够解决Ubuntu下的“Can't connect to local MySQL server through socket”错误。 [3<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Ubuntu下解决:Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2...](https://blog.csdn.net/huangdi834441642/article/details/126111703)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [Ubuntu下Can\'t connect to local MySQL server through socket的解决办法--ChinaUnix博客](https://blog.csdn.net/weixin_35531735/article/details/113906362)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文