ubantu安装mysql8 Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
时间: 2023-09-10 17:13:23 浏览: 221
uabntu安装
当在Ubuntu下安装MySQL8时,出现"Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"错误,这通常是由于MySQL服务器无法通过指定的套接字连接到本地MySQL服务器引起的。要解决这个问题,可以按照以下步骤进行操作:
1. 打开终端,使用以下命令编辑MySQL配置文件:
```
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
```
2. 在打开的文件中,找到`[mysqld]`部分,并添加以下行:
```
skip-grant-tables
```
3. 保存并关闭文件。
4. 重新启动MySQL服务:
```
sudo service mysql restart
```
这样做将启动MySQL服务器,并跳过权限验证。这样,您应该能够通过套接字连接到本地MySQL服务器了。请注意,这只是一种临时解决方法,不应在生产环境中使用。在解决问题后,请务必删除`skip-grant-tables`行,并重新启动MySQL服务器。
引用内容:
: Ubuntu下解决:Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
: Mysql数据库时,报错"can't connect to local mysql serverthrough socket'/var/run/mysqld/mysqld.sock'"
: 解决办法: sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 1 [mysqld] 2 # 3 # * Basic Settings 4 # 5 user = mysql 6 pid-file = /var/run/mysqld/mysqld.pid 7 socket = /var/run/mysqld/mysqld.sock 8 port = 3306 9 basedir = /usr 10 datadir = /var/lib/mysql 11 tmpdir = /tmp 12 lc-messages-dir = /usr/share/mysql 13 skip-external-locking 14 character-set-server=utf8 15 collation-server=utf8_general_ci 16 skip-grant-tables <-- add here<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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [Ubuntu14连接MySql报错“can't connect to local mysql server through socket '/var/run/mysqld/mysqld....](https://blog.csdn.net/qiyexuepiao/article/details/79688172)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文