在 Ubuntu 中无法连接到 mysql 数据库 [英] unable to connect to mysql database in Ubuntu

查看:178
本文介绍了在 Ubuntu 中无法连接到 mysql 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经面临这个问题好几天了.我正在尝试在 Ubuntu 机器上连接到我的 MySQL.但我不明白这一点.请查看我运行的以下命令和错误消息.

root@ipadtest:/var/lib/mysql# mysql start

<块引用>

警告:世界可写配置文件/etc/mysql/my.cnf"被忽略ERROR 2002 (HY000): 无法通过套接字连接到本地 MySQL 服务器'/var/run/mysqld/mysqld.sock' (111)

root@ipadtest:/var/lib/mysql# mysql -uroot -p

<块引用>

警告:世界可写配置文件/etc/mysql/my.cnf"被忽略输入密码:ERROR 2002 (HY000): 无法通过 socket '/var/run/mysqld/mysqld.sock' (111)

连接到本地 MySQL 服务器

root@ipadtest:/var/lib/mysql# mysqld

<块引用>

警告:世界可写配置文件/etc/mysql/my.cnf"被忽略150821 11:34:38 [错误] 致命错误:请阅读安全"部分了解如何以 root 身份运行 mysqld 的手册!

150821 11:34:38 [错误] 中止

150821 11:34:38 [注意] mysqld:关闭完成

root@ipadtest:/var/lib/mysql# mysql restart

<块引用>

警告:世界可写配置文件/etc/mysql/my.cnf"被忽略ERROR 2002 (HY000): 无法通过套接字连接到本地 MySQL 服务器'/var/run/mysqld/mysqld.sock' (111)

root@ipadtest:/var/lib/mysql# mysqladmin -u root -p status

<块引用>

警告:世界可写配置文件/etc/mysql/my.cnf"被忽略输入密码:mysqladmin:在本地主机"连接到服务器失败错误:'无法通过套接字连接到本地 MySQL 服务器'/var/run/mysqld/mysqld.sock' (111)' 检查 mysqld 是否正在运行并且套接字:'/var/run/mysqld/mysqld.sock' 存在!

谁能告诉我这是什么问题.在我看来,DB 已损坏.如果是,那么我怎样才能恢复?TIA.

解决方案

错误在警告信息中解释的很清楚,它忽略了你的my.cnf.

<块引用>

警告:世界可写配置文件/etc/mysql/my.cnf"被忽略

尝试执行以下操作,然后重新启动服务器

chown mysql:mysql/etc/mysql/my.cnfchmod 600/etc/mysql/my.cnf

这会将文件的所有者设置为 mysql 并且权限 600 将仅授予用户 mysql 读取和写入的权限文件,它将禁止所有其他用户访问.

I'm facing this problem for few days now. I'm trying to connect to my MySQL on Ubuntu machine. But I'm not getting this thru. Please see the following commands that I ran and the error messages.

root@ipadtest:/var/lib/mysql# mysql start

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

root@ipadtest:/var/lib/mysql# mysql -uroot -p

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

root@ipadtest:/var/lib/mysql# mysqld

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored 150821 11:34:38 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

150821 11:34:38 [ERROR] Aborting

150821 11:34:38 [Note] mysqld: Shutdown complete

root@ipadtest:/var/lib/mysql# mysql restart

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

root@ipadtest:/var/lib/mysql# mysqladmin -u root -p status

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored Enter password: mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)' Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

Could anyone please tell what is the issue. It seems to me that DB has been corrupted. If yes, then how can I recover? TIA.

解决方案

The error is very clearly explained in the warning message, it is ignoring your my.cnf.

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored

Try executing the following, and then restarting the server

chown mysql:mysql /etc/mysql/my.cnf
chmod 600 /etc/mysql/my.cnf

This will set the owner of the file to mysql and the permissions 600 will give only the user mysql access to read and write to the file, it will disallow access to all other users.

这篇关于在 Ubuntu 中无法连接到 mysql 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆