我不断得到错误:
错误2002(hy000):无法通过套接字'/var/run/mysqld/mysqld.sock'(2)连接到本地mysql服务器
尝试通过终端连接mysql时。
我已经完成了两个教程:
官方说法:https://help.ubuntu.com/community/mysqlpasswordreset
还有一个不太正式的:https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts
创建文件 /var/run/mysqld/mysqld.sock
在授予它权限后实际工作
chown -R mysql /var/run/mysqld chown -R mysql /var/run/mysqld/mysqld.sock
然后我可以在终端上登录mysql,修改我的主用户和根用户的密码。
运行后 sudo /etc/init.d/mysql start
或者 sudo /etc/init.d/mysql restart
我再次-无法连接到mysql使用我的用户名和密码。
service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-05-07 12:00:51 IDT; 43s ago
Process: 11057 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 11042 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 11056 (mysqld)
Tasks: 13 (limit: 4915)
Memory: 103.3M
CPU: 464ms
CGroup: /system.slice/mysql.service
└─11056 /usr/sbin/mysqld
May 07 12:00:20 asd systemd[1]: Starting MySQL Community Server...
May 07 12:00:51 asd systemd[1]: Started MySQL Community Server.
以下帖子:error 2002(hy000):无法通过socket'/var/run/mysqld/mysql.sock'连接到本地mysql服务器(2)
重新启动mysql在运行的时候并没有像帖子中提到的那样起作用 sudo /etc/init.d/mysql start
再次显示结果:
sudo /etc/init.d/mysql start
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
sh: 0: getcwd() failed: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[....] Starting mysql (via systemctl): mysql.servicejob-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[ ok job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
.
sudo service mysql start
sh: 0: getcwd() failed: No such file or directory
完全重新安装mysql是不可接受的。
一位评论人士说:
客户端设置应与服务器设置一致。
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
这很奇怪因为在我的目录里 /var/run/mysqld/
这个 mysqld.sock
文件以某种方式被删除,并且在我的 /etc/mysql/my.cnf
文件:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
# bind-address = 127.0.0.1
如何正确稳定mysql登录?为什么会这样?
跑步:
Distributor ID: Ubuntu
Description: Ubuntu 17.10
Release: 17.10
Codename: artful
1条答案
按热度按时间vxf3dgd41#
你还面临这个问题吗?可能不会,但类似的事情发生在我身上,我意识到,虽然查询运行正常,但它不会影响任何行……我修改了查询,使其只匹配“localhost”,这样就可以了:
更新mysql.user set authentication_string=password('yournewpassword'),plugin='mysql_native_password'其中user='root'和host='localhost';