gpt4 book ai didi

Ubuntu 中的 MySQL 连接

转载 作者:行者123 更新时间:2023-12-04 19:25:23 25 4
gpt4 key购买 nike

我想在 Ubuntu 中运行这个命令

mysql -uroot -p password 
我收到此错误

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

最佳答案

无法通过套接字连接到本地 MySQL 服务器
最近在我的ubuntu系统上安装的sudo数据库出现了问题。我被迫重新安装它。重装开始后,我使用mysql命令客户端连接,出现如下信息:

[LING mysql]$ mysql -u root -p

Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
我的 my.cnf 如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
port=3307
进入/var/lib/mysql,发现mysql.sock存在,但是/var/run/mysqld中不存在mysqld.sock。如果你有一个聪明的主意,你可以通过软链接(soft link)使用/var/lib/mysql/mysql.sock:
[ROOT mysqld]$ ln -s /var/lib/mysql/mysql/mysql.sock /var/run/mysqld/mysqld.sock

[ROOT mysqld]$ mysqld_safe --log-error=/var/lib/mysql/error.log &

建立链接并启动mysql,检查error.log如下:
[ROOT mysql]$ more error.log 

InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
100313 10:48:12 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
100313 10:48:12 InnoDB: Started; log sequence number 0 43655
100313 10:48:12 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.0.51a-3ubuntu5.5' socket: '/var/lib/mysql/mysql.sock' port: 3307 (Ubuntu)
[ROOT mysql]$
重新链接,成功!

关于Ubuntu 中的 MySQL 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71676520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com