简体   繁体   English

错误 2002 (HY000): 无法通过套接字'/var/run/mysqld/mysqld.sock' (2) 连接到本地 MySQL 服务器

[英]ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I installed LAMP on Ubuntu 12.04 LTS (Precise Pangolin) and then set root password on phpMyAdmin .我在Ubuntu 12.04 LTS (Precise Pangolin) 上安装了LAMP ,然后在phpMyAdmin上设置了 root 密码。 I forgot the password and now I am unable to login.我忘记了密码,现在无法登录。 When I try to change password through terminal I get:当我尝试通过终端更改密码时,我得到:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)错误 2002 (HY000): 无法通过套接字'/var/run/mysqld/mysqld.sock' (2) 连接到本地 MySQL 服务器

How can I fix this?我怎样才能解决这个问题? I am unable to open LAMP, uninstall it or reinstall it.我无法打开、卸载或重新安装 LAMP。

I once had this problem and solved it by installing mysql-server , so make sure that you have installed the mysql-server , not the mysql-client or something else.我曾经遇到过这个问题并通过安装mysql-server解决了它,所以请确保您已经安装了mysql-server ,而不是mysql-client或其他东西。

That error means the file /var/run/mysqld/mysqld.sock doesn't exists, if you didn't install mysql-server , then the file would not exist.该错误意味着文件/var/run/mysqld/mysqld.sock不存在,如果您没有安装mysql-server ,则该文件将不存在。 So in that case, install it with所以在这种情况下,安装它

sudo apt-get install mysql-server

But if the mysql-server is already installed and is running, then you need to check the config files.但是如果mysql-server已经安装并且正在运行,那么你需要检查配置文件。

The config files are:配置文件是:

/etc/my.cnf
/etc/mysql/my.cnf
/var/lib/mysql/my.cnf

In /etc/my.cnf , the socket file config may be /tmp/mysql.sock and in /etc/mysql/my.cnf the socket file config may be /var/run/mysqld/mysqld.sock ./etc/my.cnf中,套接字文件配置可能是/tmp/mysql.sock ,而在/etc/mysql/my.cnf中,套接字文件配置可能是/var/run/mysqld/mysqld.sock So, remove or rename /etc/mysql/my.cnf , let mysql use /etc/my.cnf , then the problem may solved.所以,删除或重命名/etc/mysql/my.cnf ,让 mysql 使用/etc/my.cnf ,那么问题可能就解决了。

Try this:尝试这个:

mysql -h 127.0.0.1 -P 3306 -u root -p <database>

Also (to see if it's running):另外(查看它是否正在运行):

telnet 127.0.0.1 3306 

Probably it is just a misconfiguration in the my.cnf file, in /etc/somewhere (depending on the Linux distribution ).可能这只是/etc/somewhere中的my.cnf文件中的错误配置(取决于Linux 发行版)。

I am seeing all these answers, but none offer the option to reset the password and no accepted answer .我看到了所有这些答案,但没有一个提供重置密码的选项并且没有接受的答案 The actual question being he forgot his password, so he needs to reset, not see if it's running or not (installed or not) as most of these answers imply.实际的问题是他忘记了密码,所以他需要重置,而不是查看它是否正在运行(安装与否),因为这些答案中的大多数暗示。


To reset the password重置密码

Follow these steps (can be helpful if you really forget your password and you can try it anytime, even if you're not in the situation at the moment):请按照以下步骤操作(如果您真的忘记了密码会很有帮助,并且您可以随时尝试,即使您目前不在这种情况下):

  1. Stop mysql停止mysql

     sudo /etc/init.d/mysql stop

    Or for other distribution versions:或者对于其他发行版本:

     sudo /etc/init.d/mysqld stop
  2. Start MySQL in safe mode以安全模式启动 MySQL

     sudo mysqld_safe --skip-grant-tables &
  3. Log into MySQL using root使用 root 登录 MySQL

     mysql -u root
  4. Select the MySQL database to use选择要使用的 MySQL 数据库

    use mysql;
  5. Reset the password重置密码

    -- MySQL version < 5.7 update user set password=PASSWORD("mynewpassword") where User='root'; -- MySQL 5.7, mysql.user table "password" field -> "authentication_string" update user set authentication_string=password('mynewpassword') where user='root';
  6. Flush the privileges刷新权限

    flush privileges;
  7. Restart the server重启服务器

    quit
  8. Stop and start the server again停止并重新启动服务器

    Ubuntu and Debian: Ubuntu 和 Debian:

     sudo /etc/init.d/mysql stop ... sudo /etc/init.d/mysql start

On CentOS, Fedora, and RHEL:在 CentOS、Fedora 和 RHEL 上:

    sudo /etc/init.d/mysqld stop
    ...
    sudo /etc/init.d/mysqld start
  1. Login with a new password使用新密码登录

    mysql -u root -p
  2. Type the new password and enjoy your server again like nothing happened输入新密码并再次享受您的服务器,就像什么都没发生一样

This was taken from Reset a MySQL root password .这取自Reset a MySQL root password

I tried the following steps:我尝试了以下步骤:

  1. Log in as super user or use sudosuper user身份登录或使用sudo
  2. Open /etc/mysql/my.cnf using gedit使用gedit打开/etc/mysql/my.cnf
  3. Find bind-address , and change its value to the database server host machine's IP address.找到bind-address ,并将其值更改为数据库服务器主机的 IP 地址。 For me, it was localhost or 127.0.0.1对我来说,它是localhost127.0.0.1
  4. Save and close the file.保存并关闭文件。
  5. Come back to terminal and execute sudo service mysql start回到终端执行sudo service mysql start

And it worked for me.它对我有用。

In my case it was that the disk was full and mysqld couldn't start anymore.在我的情况下,磁盘已满,mysqld 无法再启动。

Try to restart mysql service.尝试重启mysql服务。

> service mysql restart

or或者

> service mysql stop

> service mysql start

If it doesn't recognize stop command then it's definitely the disk space.如果它不识别stop命令,那么它肯定是磁盘空间。 You should make some space in the partition mysql is allocated or make the disk larger.您应该在分配mysql的分区中腾出一些空间或使磁盘更大。

Check the disk space with检查磁盘空间

> df -h

I fixed this problem by executing the following command:我通过执行以下命令解决了这个问题:

mysql.server start

And if you are on a mac and used brew to install mysql, simply use:如果您在 Mac 上并使用 brew 安装 mysql,只需使用:

brew services start mysql

I had a similar problem.我有一个类似的问题。 mysql wouldn't start: mysql 无法启动:

sudo service mysql start
start: Job failed to start

If I disabled apparmor:如果我禁用 apparmor:

sudo aa-complain /etc/apparmor.d/*

the problem went away.问题消失了。 The issue was that mysqld was trying to access /run/mysqld/mysqld.sock but the apparmor profile only gave permission to /var/run/mysqld/mysqld.sock (/var/run is symlinked to /run, so these are actually the same).问题是 mysqld 试图访问 /run/mysqld/mysqld.sock 但 apparmor 配置文件只授予 /var/run/mysqld/mysqld.sock 权限(/var/run 符号链接到 /run,所以这些实际上是相同)。 Not sure why mysqld isn't using the var path since that's what's set in all the configuration files, but you can fix the problem by adding the following to /etc/apparmor.d/usr.sbin.mysqld不知道为什么 mysqld 不使用 var 路径,因为这是在所有配置文件中设置的,但是您可以通过将以下内容添加到 /etc/apparmor.d/usr.sbin.mysqld 来解决问题

/run/mysqld/mysqld.pid rw,
/run/mysqld/mysqld.sock rw,

I solved this by killing the mysql process:我通过杀死mysql进程解决了这个问题:

ps -ef | grep mysql
kill [the id]

And then I started the server again with:然后我再次启动服务器:

sudo /etc/init.d/mysql restart

But start works as well:但是start也可以:

sudo /etc/init.d/mysql start

Then I logged in as admin , and I was done.然后我以admin身份登录,我就完成了。

Somehow the MySQL server process did not create the socket, or the client is looking for the socket in the wrong place.不知何故,MySQL 服务器进程没有创建套接字,或者客户端在错误的位置寻找套接字。

My first suggestion would be to check if the MySQL server is running.我的第一个建议是检查 MySQL 服务器是否正在运行。 Second suggestion might be, is the MySQL server running on another host?第二个建议可能是,MySQL 服务器是否在另一台主机上运行? If so, add the -h <hostname> flag to your MySQL client in the terminal.如果是这样,请将-h <hostname>标志添加到终端中的 MySQL 客户端。

If MySQL is indeed running, and running locally, check your my.cnf file.如果 MySQL 确实在运行,并且在本地运行,请检查您的my.cnf文件。 There should be a line like应该有一条线

socket = /var/run/mysqld/mysqld.sock

See if that matches the socket location that you mentioned in your post.看看这是否与您在帖子中提到的套接字位置相匹配。

From experience, I would say the most likely scenario is your MySQL server either is not running at all or is not running on the same host as where you run your MySQL client from the terminal.根据经验,我想说最有可能的情况是您的 MySQL 服务器根本没有运行,或者没有在与您从终端运行 MySQL 客户端的主机上运行。

I just experienced the same issue after I had to restart my production server.在我不得不重新启动生产服务器后,我刚刚遇到了同样的问题。 I am running Debian 8.1 (Jessie) on a DigitalOcean droplet.我在 DigitalOcean 液滴上运行 Debian 8.1 (Jessie)。

This is what I did to resolve my issue:这是我为解决我的问题所做的:

  1. Check if the file /var/run/mysqld/mysqld.sock exists.检查文件/var/run/mysqld/mysqld.sock是否存在。 If it doesn't, manually create it by entering touch /var/run/mysqld/mysqld.sock (which is what I had to do).如果没有,请通过输入touch /var/run/mysqld/mysqld.sock手动创建它(这是我必须做的)。

  2. So the MySQL process can use this file.所以 MySQL 进程可以使用这个文件。 Change ownership of said file by entering chown mysql /var/run/mysqld/mysqld.sock .通过输入chown mysql /var/run/mysqld/mysqld.sock更改所述文件的所有权。

  3. Once '2' has been done, restart the MySQL service by entering service mysql restart or /etc/init.d/mysql restart .完成“2”后,通过输入service mysql restart/etc/init.d/mysql restart启动 MySQL 服务。

After going through the above steps, my issue was solved.完成以上步骤后,我的问题就解决了。 I rarely have this issue, and there is probably a better way, so by all means provide constructive feedback if need be :).我很少遇到这个问题,可能有更好的方法,所以如果需要的话,一定要提供建设性的反馈:)。

Check the "bind-adress" parameter in my.cnf.检查 my.cnf 中的"bind-adress"参数。

Else try with the command:否则尝试使用以下命令:

mysql -h 127.0.0.1 -P 3306 -u root -p
  • -h for host 127.0.0.1 , that is, localhost -h 代表主机127.0.0.1 ,即 localhost

  • -P (notice -P as uppercase) for port 3306 , that is, the default port for MySQL -P (注意 -P 为大写)用于端口3306 ,即 MySQL 的默认端口

Your mysql-server might not be running.您的 mysql-server 可能没有运行。 Ensure it runs by typing mysql.server start into the terminal.通过在终端中键入mysql.server start确保它运行。

I think whenever you get the error我想每当你得到错误

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'错误 2002 (HY000): 无法通过套接字 '/var/lib/mysql/mysql.sock' 连接到本地 MySQL 服务器

I will recommend first to check whether your mysql daemon is running... Most of the time it will not running by default.我会建议首先检查您的mysql守护进程是否正在运行......大多数情况下它不会默认运行。 You can check it by /etc/init.d/mysqld status .您可以通过/etc/init.d/mysqld status检查它。

If it's not running then start it first:如果它没有运行,请先启动它:

.../etc/init.d/mysqld start.

I bet it will 110% work.我敢打赌它会 110% 工作。

If you're using Amazon EC2 , and you're having this problem on the instance, then you only need to do:如果您使用的是Amazon EC2 ,并且您在实例上遇到此问题,那么您只需执行以下操作:

sudo yum install mysql-server
sudo service mysqld restart

Amazon EC2 doesn't have a server installed (only the client is installed), so in case of that you need to install that on your instance, and after that try Amazon EC2 没有安装服务器(仅安装了客户端),因此如果出现这种情况,您需要在您的实例上安装它,然后尝试

 mysql -u root -p

to check if that worked.检查是否有效。

Here's what worked for me:这对我有用:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
service mysql restart

This creates a link.这将创建一个链接。

Instead of using localhost:而不是使用本地主机:

mysql -u myuser -pmypassword -h localhost mydatabase

Use 127.0.0.1使用 127.0.0.1

mysql -u myuser -pmypassword -h 127.0.0.1 mydatabase

(also note, no space between -p and mypassword) (另请注意,-p 和 mypassword 之间没有空格)

Enjoy :)享受 :)

Make sure you have backups of important databases and then try uninstall MySQL related stuff:确保你有重要数据库的备份,然后尝试卸载 MySQL相关的东西:

apt-get remove --purge mysql\*

Then install it again :然后再次安装

apt-get install mysql-server mysql-client

This worked for me and data was kept.这对我有用,并且保留了数据。

If PHP MySQL shows errors you might have to reinstall PHP MySQL :如果 PHP MySQL 显示错误,您可能需要重新安装 PHP MySQL

apt-get install php5-fpm php5-mysql

I also facing same problem it will be occur if your mysql server is not running by default it will again stop after some sec so you again run ( $ sudo service mysql start ) command you can change if know.我也面临同样的问题,如果你的mysql server默认没有运行,它会在几秒钟后再次停止,所以你再次运行( $ sudo service mysql start )命令,如果知道,你可以更改。

for that use command对于那个使用命令

$ sudo service mysql start   

(put user password if required because we use sudo ) and then run (如果需要,请输入用户密码,因为我们使用sudo )然后运行

$ sudo mysql -u root -p          (put user password if required )

now you got your database现在你有了你的数据库

I got this problem too, but I just did:我也遇到了这个问题,但我只是这样做了:

sudo service mysql restart 

It worked for me.它对我有用。

It seems your MYSQL is stopped.看来您的 MYSQL 已停止。 use below command to start MySQL again使用以下命令再次启动 MySQL

sudo service mysql start

I FOUND THE SOLUTION我找到了解决方案

Before firing the command : mysql_secure_installation在触发命令之前: mysql_secure_installation

  • Step 1: sudo systemctl stop mariadb第 1 步: sudo systemctl stop mariadb
  • Step 2: sudo systemctl start mariadb第 2 步: sudo systemctl start mariadb
  • Step 3: mysql_secure_installation第 3 步: mysql_secure_installation

Then it will ask root password and you can simply press Enter and set your new root password.然后它会询问 root 密码,您只需Enter并设置新的 root 密码。

如果您的安装是最近的,您应该确认您的安装是否是安装服务器... as mysql-server-5.5 .. 也许您只安装了“mysql” .. 这只是客户端而不是服务器。

If you have XAMPP installed on your Linux machine, try to copy your my.cnf file from /opt/lampp/etc/my.cnf to /etc/my.cnf .如果您的 Linux 机器上安装了XAMPP ,请尝试将my.cnf文件从/opt/lampp/etc/my.cnf复制到/etc/my.cnf

Then, run the mysql -u root again... You should now have the correct socket and be able to run the MySQL client.然后,再次运行mysql -u root ...您现在应该拥有正确的套接字并能够运行 MySQL 客户端。

In my case, the default port 3306 was being used by some other process and thus it was not starting.在我的情况下,默认端口 3306 正在被其他进程使用,因此它没有启动。 After I stopped the other service and did sudo service mysql start , it worked fine.在我停止其他服务并执行sudo service mysql start后,它工作正常。 BTW, you can use something like sudo lsof -Pn -iTCP:3306 to see who may be using the port.顺便说一句,您可以使用sudo lsof -Pn -iTCP:3306类的东西来查看谁可能正在使用该端口。

In my case it worked by doing some R&D:就我而言,它通过一些研发工作:

I am able to connect to MySQL using我可以使用连接到 MySQL

root-debian#mysql -h 127.0.0.1 -u root -p

But it's not working with mysql -u root -p .但它不适用于mysql -u root -p

I did not find any bind-address in my.cnf .我在my.cnf中没有找到任何bind-address So I outcommented the parameter socket=/var/lib/mysql/mysqld.sock in my.cnf which was causing me a problem with login.因此,我在my.cnf中对参数socket=/var/lib/mysql/mysqld.sock进行了注释,这导致我出现登录问题。

After restarting the service it went fine:重启服务后一切正常:

root@debian:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.19 MySQL Community Server (GPL)

In my case, It seems like I wasnt really able to kill the mysql process, when I run就我而言,当我运行时,似乎我真的无法杀死 mysql 进程

sudo service mysql stop
ps -ef | grep mysql

The mysql process was always there, it looks like it was blocking the socket file and new mysql process wasnt able to create it itself. mysql 进程一直在那里,看起来它正在阻塞套接字文件,并且新的 mysql 进程无法自己创建它。

so this helped所以这有帮助

cd /var/run
sudo cp mysqld/ mysqld.bc -rf
sudo chown mysql:mysql mysqld.bc/
sudo service mysql stop
sudo cp mysqld.bc/ mysqld -rf
sudo chown mysql:mysql mysqld -R
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

Now Im able to log in database using现在我可以使用登录数据库

mysql -u root

Then to update root password:然后更新root密码:

UPDATE user SET authentication_string=password('YOURPASSWORDHERE') WHERE user='root';
FLUSH PRIVILEGES;

PS : I had trouble updating root passwod, seems like problem with "auth_socket" plugin, so I had to create new user with full privileges PS :我在更新 root 密码时遇到了问题,似乎是“auth_socket”插件的问题,所以我必须创建具有完全权限的新用户

insert into user set `Host` = "localhost", `User` = "super", `plugin` = "mysql_native_password", `authentication_string` = NULL, `password_expired` = "N", `password_lifetime` = NULL, `account_locked` = "N", `Select_priv` = "Y",
`Insert_priv` = "Y", `Update_priv` = "Y", `Delete_priv` = "Y", `Create_priv` = "Y", `Drop_priv` = "Y", `Reload_priv` = "Y", `Shutdown_priv` = "Y", `Process_priv` = "Y", `File_priv` = "Y",
`Grant_priv` = "Y",  `References_priv` = "Y", `Index_priv` = "Y", `Alter_priv` = "Y", `Show_db_priv` = "Y", `Super_priv` = "Y", `Create_tmp_table_priv` = "Y", `Lock_tables_priv` = "Y",
`Execute_priv` = "Y", `Repl_slave_priv` = "Y",  `Repl_client_priv` = "Y",  `Create_view_priv` = "Y", `Show_view_priv` = "Y", `Create_routine_priv` = "Y", `Alter_routine_priv` = "Y",
`Create_user_priv` = "Y",  `Event_priv` = "Y", `Trigger_priv` = "Y", `Create_tablespace_priv` = "Y";

This creates user "super" with no password and then you can connect with mysql -u super这将创建没有密码的用户“super”,然后您可以使用mysql -u super进行连接

On Debian server Jessie, my working solution was to simply do在 Debian 服务器 Jessie 上,我的工作解决方案是简单地做

service mysql restart
service mysql reload

as root user作为根用户

i solved this problem with restart mysql我用重启mysql解决了这个问题

/etc/init.d/mysql stop

and

/etc/init.d/mysql start

that's it.而已。

Fist,try to restart it with拳头,尝试重新启动它

service mysql stop服务 mysql 停止

service mysql start服务 mysql 启动

If above not resolve the issue, now let's go...如果上面没有解决问题,现在让我们去......

Uninstall completely MySQL完全卸载 MySQL

sudo apt-get remove --purge mysql\*

reinstall it重新安装它

sudo apt install mysql-server mysql-client

test if it run测试它是否运行

sudo mysql

Install php drivers安装php驱动

sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-cgi php7.4-cli php7.4-common

You can replace php7.4 by php7.x or php8.0.12 or later Very nice !您可以用 php7.x 或 php8.0.12 或更高版本替换 php7.4 非常好!

❗️Be careful, you lose your data if they are not saved. ❗️小心,如果不保存数据,您将丢失数据。 Please backup your data if possible yet.如果可能,请备份您的数据。

By experience I say that you need to check if the server is running first and then try configuring MySQL.根据经验,我说您需要先检查服务器是否正在运行,然后再尝试配置 MySQL。 The last solution is to re-install MySQL.最后的解决方案是重新安装 MySQL。

Check if you have the correct rights:检查您是否拥有正确的权限:

sudo chmod 755 /var/lib/mysql/mysql

I had the same problems and this worked for me.我有同样的问题,这对我有用。 After doing this I was able to start MySQL.完成此操作后,我能够启动 MySQL。

The same on Ubuntu 14.04 (Trusty Tahr).在 Ubuntu 14.04 (Trusty Tahr) 上也是如此。

If you have installed XAMPP, installing mysql-server isn't the solution, because you'll access another MySQL!如果您已经安装了 XAMPP,安装 mysql-server 不是解决方案,因为您将访问另一个 MySQL!

You have to use the right socket to access.您必须使用正确的套接字才能访问。 Usually it is this:通常是这样的:

/opt/lampp/var/mysql/mysql.sock

Instead, change it to:相反,将其更改为:

/var/run/mysqld/mysqld.sock

Open the terminal and type:打开终端并输入:

sudo apt-get purge mysql-client-core-5.6

sudo apt-get autoremove

sudo apt-get autoclean

sudo apt-get install mysql-client-core-5.5

sudo apt-get install mysql-server  

Both MySQL database core client and MySQL Server packages will be the same version 5.5. MySQL 数据库核心客户端和 MySQL 服务器包都将是相同的 5.5 版本。 MySQL Client 5.5 and MySQL Server 5.5 are the current "best" versions of these packages in Ubuntu 14.04 as determined by the package maintainers. MySQL Client 5.5 和 MySQL Server 5.5 是 Ubuntu 14.04 中这些软件包的当前“最佳”版本,由软件包维护者确定。

If you would rather install MySQL Client 5.6 and MySQL Server 5.6 you can also find the mysql-client-core-5.6 and mysql-server-5.6 packages in the Ubuntu Software Center.如果您希望安装 MySQL Client 5.6 和 MySQL Server 5.6,您还可以在 Ubuntu 软件中心找到 mysql-client-core-5.6 和 mysql-server-5.6 软件包。 The important thing is that the client and server version numbers match in either case.重要的是客户端和服务器版本号在任何一种情况下都匹配。

This worked for me.这对我有用。

mysqld stop
mysql.server start

I had the same problem.我有同样的问题。 After much searching I didn't find any answer.经过大量搜索,我没有找到任何答案。

At last, I checked the /tmp directory, and its permissions were 755. I changed its permissions to 777 and mysqld started well without any problem.最后查看/tmp目录,权限为755,改成777,mysqld启动正常,没有任何问题。

I had the same issue.我遇到过同样的问题。 Sometimes this happens if your MySQL service is turned down.如果您的 MySQL 服务被关闭,有时会发生这种情况。

So you have to start it:所以你必须启动它:

sudo service mysql start

For me an update solved the problem:对我来说,更新解决了这个问题:

On Ubuntu:在 Ubuntu 上:

sudo apt-get update
sudo apt-get upgrade

On CentOS:在 CentOS 上:

sudo yum update

It works now...它现在工作...

I have followed the tutorial Installing MariaDB 10.1.16 on Mac OS X with Homebrew to overcome this issue.我已经按照教程在 Mac OS X 上使用 Homebrew 安装 MariaDB 10.1.16来克服这个问题。

But don't forget to kill or uninstall the old installation of MariaDB.但是不要忘记杀死或卸载旧的 MariaDB 安装。

You are missing permission to create /var/run/mysqld directory.So please create and give permission as following.您缺少创建 /var/run/mysqld 目录的权限。所以请创建并授予以下权限。

  • mkdir -p /var/run/mysqld mkdir -p /var/run/mysqld
  • chown mysql:mysql /var/run/mysqld chown mysql:mysql /var/run/mysqld

Try restarting the server with尝试重新启动服务器

sudo /usr/local/mysql/support-files/mysql.server start

If there is any error then follow the below steps如果有任何错误,请按照以下步骤操作

  1. mysqld

You will see the the below log.您将看到以下日志。 Notice the highlighted portion of the MySQL directory here请注意此处 MySQL 目录的突出显示部分

mysqld: Can't change dir to '/usr/local/mysql-5.7.14-osx10.11-x86_64/data/' (Errcode: 13 - Permission denied) 2016-10-04T14:09:19.392581Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. mysqld:无法将目录更改为“/usr/local/mysql-5.7.14-osx10.11-x86_64/data/” (错误代码:13 - 权限被拒绝)2016-10-04T14:09:19.392581Z 0 [警告] 带有隐式 DEFAULT 值的 TIMESTAMP 已弃用。 Please use --explicit_defaults_for_timestamp server option (see documentation for more details).请使用 --explicit_defaults_for_timestamp 服务器选项(有关详细信息,请参阅文档)。 2016-10-04T14:09:19.392847Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. 2016-10-04T14:09:19.392847Z 0 [警告] --secure-file-priv 的不安全配置:当前值不限制生成文件的位置。 Consider setting it to a valid, non-empty path.考虑将其设置为有效的非空路径。 2016-10-04T14:09:19.392921Z 0 [Note] mysqld (mysqld 5.7.14) starting as process 1402 ... 2016-10-04T14:09:19.397569Z 0 [Warning] Can't create test file 2016-10-04T14:09:19.392921Z 0 [注意] mysqld (mysqld 5.7.14) 从进程 1402 开始 ... 2016-10-04T14:09:19.397569Z 0 [警告] 无法创建测试文件
/usr/local/mysql-5.7.14-osx10.11-x86_64/data/Sudharshan.lower-test /usr/local/mysql-5.7.14-osx10.11-x86_64/data/Sudharshan.lower-test
2016-10-04T14:09:19.397597Z 0 [Warning] Can't create test file /usr/local/mysql-5.7.14-osx10.11-x86_64/data/Sudharshan.lower-test 2016-10-04T14:09:19.397597Z 0 [警告] 无法创建测试文件 /usr/local/mysql-5.7.14-osx10.11-x86_64/data/Sudharshan.lower-test
2016-10-04T14:09:19.397712Z 0 [ERROR] failed to set datadir to /usr/local/mysql-5.7.14-osx10.11-x86_64/data/ 2016-10-04T14:09:19.397712Z 0 [错误] 未能将 datadir 设置为 /usr/local/mysql-5.7.14-osx10.11-x86_64/data/
2016-10-04T14:09:19.397776Z 0 [ERROR] Aborting 2016-10-04T14:09:19.397776Z 0 [错误] 中止
2016-10-04T14:09:19.397795Z 0 [Note] Binlog end 2016-10-04T14:09:19.397795Z 0 [注意] Binlog 结束
2016-10-04T14:09:19.397925Z 0 [Note] mysqld: Shutdown complete 2016-10-04T14:09:19.397925Z 0 [注意] mysqld:关闭完成

  1. sudo chown -R _mysql:_mysql /usr/local/mysql-5.7.14-osx10.11-x86_64

Note the MySQL folder path /usr/local on the the previous log, and in my case it was mysql-5.7.14-osx10.11-x86_64 , and you have to update it based on the log you get on your machine to provide read access to the MySQL directory注意上一个日志中的 MySQL 文件夹路径/usr/local ,在我的例子中是mysql-5.7.14-osx10.11-x86_64 ,你必须根据你机器上提供的日志来更新它对 MySQL 目录的读取权限

  1. sudo /usr/local/mysql/support-files/mysql.server start

Starting MySQL启动 MySQL
SUCCESS!成功!

For CentOS Linux release 7.3 The mysql.sock file path is /var/lib/mysql/mysql.sock对于 CentOS Linux 7.3 版 mysql.sock 文件路径是/var/lib/mysql/mysql.sock

Edit /etc/my.cnf file and put below entry This will solve your problem.编辑/etc/my.cnf文件并在下面输入这将解决您的问题。

[client]
user=root
password=Passw0rd
port=3306
socket=/var/lib/mysql/mysql.sock
[mysqld]
bind-address=0.0.0.0

After this restart the service在此之后重新启动服务

service mysql restart

I got exactely the same error when I have stopped mysql service, and here how to solve it: by (re)starting mysql using these commands:当我停止 mysql 服务时,我得到了完全相同的错误,在这里如何解决它:通过使用以下命令(重新)启动 mysql:

sudo systemctl start mysql

or或者

sudo systemctl restart mysql

对我来说 mysql 没有运行,所以我修复了它

sudo /etc/init.d/mysql start

You could first check whether the service is running, with:您可以首先检查服务是否正在运行,使用:

ps ax | grep mysql

I got this response:我得到了这样的回应:

6104 pts/0    S      0:00 /bin/sh /usr/bin/mysqld_safe
6431 pts/0    Sl     0:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --pid-file=/var/run/mysqld/m

No response means the service isn't running, so do:没有响应意味着服务没有运行,所以这样做:

service  mysql start

In my case, the problem was page corruption in all my databases (check the mysql error log).就我而言,问题是我所有数据库中的页面损坏(检查 mysql 错误日志)。

I solved it with Forcing InnoDB Recovery .我用强制 InnoDB Recovery解决了它。 The trick is editing /etc/mysql/my.cnf and adding诀窍是编辑 /etc/mysql/my.cnf 并添加

innodb_force_recovery = 4

just below略低于

[mysqld]

And then restart mysql.然后重启mysql。 After checking everything works correctly now, remove the line back again.现在检查一切正常后,再次删除线。

Just copy your /opt/lampp/etc/my.cnf file to /etc/mysql/my.cnf .只需将您的/opt/lampp/etc/my.cnf文件复制到/etc/mysql/my.cnf即可。

And in the terminal type:在终端类型中:

mysql -u root

You will be getting the mysql> prompt:您将获得mysql>提示:

mysql> Update mysql.user set Password=PASSWORD('your_password') where user='root';

mysql> FLUSH PRIVILEGES;

Install mysql-server:安装mysql服务器:

sudo apt-get install mysql-server
enter password as root

Login:登录:

mysql -u root -p root

Here -u user name and -p password was given while installing MySQL server.这里-u user name-p password是在安装 MySQL 服务器时给出的。 It will work as it has worked for me.它会像对我一样有效。

My server storage was full, this was preventing Mysql from starting.我的服务器存储已满,这导致 Mysql 无法启动。 Got the idea from here .这里得到想法。 Increasing the HD and rebooting fixed the issue.增加 HD 并重新启动解决了该问题。

In my case, I'm not able to access mysql and after 3 days research, I have got a solution.就我而言,我无法访问 mysql,经过 3 天的研究,我找到了解决方案。 This is perfect solution because I have searched /var/run/mysqld/mysqld.sock and I did not find the folder.这是完美的解决方案,因为我搜索了/var/run/mysqld/mysqld.sock但没有找到该文件夹​​。 You can run on putty the commands listed below.您可以在 putty 上运行下面列出的命令。

sudo mkdir /var/run/mysqld/
sudo chown -R mysql:mysql /var/log/mysql
sudo mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --socket=/var/run/mysqld/mysqld.sock
sudo /etc/init.d/mysql restart

You will save your valuable time.您将节省宝贵的时间。

I can't explain it, but in kubuntu 12.04.2 after我无法解释,但在 kubuntu 12.04.2 之后

sudo apt-get autoremove linux-headers-3.2.0-37 linux-headers-3.2.0-37-generic sudo apt-get autoremove linux-headers-3.2.0-37 linux-headers-3.2.0-37-generic

it started to work它开始起作用了

If you're using Ubuntu, it could be a matter of privileges.如果您使用的是 Ubuntu,则可能是权限问题。

Check your directory privileges.检查您的目录权限。 It's not enough to be in the root group, also use a chmod on directories which MySQL writes (for example, /var/run/mysqld/ for the creation of the mysqld.pid file).仅仅在根组中是不够的,还要在 MySQL 写入的目录上使用chmod (例如, /var/run/mysqld/用于创建mysqld.pid文件)。

This was helpful for me.这对我很有帮助。

To prevent the problem from occurring, you must perform a graceful shutdown of the server from the command line rather than powering off the server.为防止发生此问题,您必须从命令行正常关闭服务器,而不是关闭服务器电源。

shutdown -h now

This will stop the running services before powering down the machine.这将在关闭机器之前停止正在运行的服务。

Based on Centos, an additional method for getting it back up again when you run into this problem is to move mysql.sock:基于 Centos,当你遇到这个问题时,另一种方法是移动 mysql.sock:

mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak

service mysqld start

Restarting the service creates a new entry called mqsql.sock重新启动服务会创建一个名为 mqsql.sock 的新条目

I just had this problem now and solved it.我现在刚刚遇到这个问题并解决了。

Although you installed mysql-server, the daemon needs to be running in order for the client to connect to it.尽管您安装了 mysql-server,但需要运行守护程序才能让客户端连接到它。

First check to see if mysql server is running:首先检查mysql服务器是否正在运行:

netstat -tap | grep mysql

You should see something like this:您应该看到如下内容:

$ sudo netstat -tap | grep mysql
tcp        0      0 localhost:mysql         *:*          LISTEN     6639/mysqld     

If you don't have the server running, start the daemon by the following command:如果您没有运行服务器,请通过以下命令启动守护程序:

/etc/init.d/mysql restart

This should solve your problem if it's installed.如果已安装,这应该可以解决您的问题。

You are running locally, meaning that your client runs on the same machine as your server.您在本地运行,这意味着您的客户端与您的服务器在同一台机器上运行。

Make sure that your Unix user can actually reach/read /var/run/mysqld/mysqld.sock :确保您的 Unix 用户实际上可以访问/读取/var/run/mysqld/mysqld.sock

ls -als /var
ls -als /var/run
ls -als /var/run/mysqld
ls -als /var/run/mysqld/mysqld.sock

If not, check with your system administrator or database administrator to provide adequate read/execute access to those directories, or move the socket file elsewhere.如果没有,请咨询您的系统管理员或数据库管理员,以提供对这些目录的足够读取/执行访问权限,或将套接字文件移至其他位置。

Also check your my.conf ( /etc/mysql/my.cnf ) and see if bind-address is set to 127.0.0.1.还要检查您的my.conf ( /etc/mysql/my.cnf ) 并查看 bind-address 是否设置为 127.0.0.1。

If not, this might cause this issue.如果不是,这可能会导致此问题。

I had the same issue.我遇到过同样的问题。 I found this.我找到了这个。

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

This is because you are not running the mysqld daemon before launching the MySQL client.这是因为在启动 MySQL 客户端之前您没有运行mysqld守护进程。 The file /var/lib/mysql/mysql.sock will be automatically created upon running the first instance of MySQL. /var/lib/mysql/mysql.sock文件将在运行第一个 MySQL 实例时自动创建。

To fix:修理:

First start the MySQL daemon, then type mysql :首先启动 MySQL 守护进程,然后键入mysql

/etc/init.d/mysqld start
mysql

Changing MySQL Root Password更改 MySQL 根密码

By default, the root password is empty for the MySQL database.默认情况下,MySQL 数据库的 root 密码为空。 It is a good idea to change the MySQL root password to a new one from a security point of view.从安全的角度来看,将 MySQL root 密码更改为新密码是个好主意。

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';
mysql> FLUSH PRIVILEGES;

Once done, check by logging in:完成后,通过登录检查:

mysql -u root -p
Enter Password: <your new password>

This answer is related to updating to MySQL 5.6 on machines with a small amount of RAM这个答案与在具有少量 RAM 的机器上更新到 MySQL 5.6 有关

I had the same problem when upgrading from MySQL 5.5 to 5.6 on my Debian 8 (Jessie).在我的 Debian 8 (Jessie) 上从 MySQL 5.5 升级到 5.6 时,我遇到了同样的问题。 MySQL was not started (the status was showing active/exited) and simply making service mysql start did not work, because as I found from the /var/logs/mysql/error.log log file: MySQL 没有启动(状态显示为活动/退出),只是让service mysql start不起作用,因为我从/var/logs/mysql/error.log日志文件中发现:

InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(136019968 bytes) failed; errno 12
Cannot allocate memory for the buffer pool

The memory was not enough: I had only 256 MB of RAM.内存不够:我只有 256 MB 的 RAM。

In MySQL there is a setting, performance_schema .在 MySQL 中有一个设置performance_schema By default, it is turned off in MySQL 5.5.默认情况下,它在 MySQL 5.5 中是关闭的。

https://dev.mysql.com/doc/refman/5.5/en/performance-schema-startup-configuration.html https://dev.mysql.com/doc/refman/5.5/en/performance-schema-startup-configuration.html

But in MySQL 5.6 the default is on, and simply by adding the following line in /etc/mysql/my.cnf file and restarting, it worked.但是在 MySQL 5.6 中默认是打开的,只需在/etc/mysql/my.cnf文件中添加以下行并重新启动,它就可以工作了。

performance_schema = off

Warning: Turning this setting off you might experience performance issues, but I guess in a development environment it won't be a problem.警告:关闭此设置您可能会遇到性能问题,但我想在开发环境中不会有问题。

Also, here is an article that might be helpful configuring MySQL to use minimal memory, Configuring MySQL to use minimal memory (web archive link in case the original link expires in the future https://web.archive.org/web/20201112041608/http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html ).另外,这里有一篇文章可能有助于配置 MySQL 以使用最少的内存, 配置 MySQL 以使用最少的内存(Web 存档链接,以防原始链接将来过期https://web.archive.org/web/20201112041608/ http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html )。

An advice: Always ask MySQL what the problem is.一个建议:总是问 MySQL 问题是什么。 In my case, less /var/log/mysql/error.log and see this:在我的情况下, less /var/log/mysql/error.log并看到这个:

2015-07-28 12:01:48 23224 [ERROR] /usr/sbin/mysqld: unknown variable 'log_slow_queries=/var/log/mysql/mysql-slow.log'
2015-07-28 12:01:48 23224 [ERROR] Aborting

It is complaining, because I uncommented this option in my.cnf , but after commenting this option, it started without any problem.它在抱怨,因为我在my.cnf中取消了这个选项的注释,但是在注释了这个选项之后,它开始没有任何问题。

For me it was:对我来说是:

Open /etc/mysql/my.cnf or /etc/my.cnf and search for 'bind-address'.打开/etc/mysql/my.cnf/etc/my.cnf并搜索“bind-address”。 It was 127.0.0.1 .它是127.0.0.1 I converted it to localhost, so the line result should be 'bind-address = localhost'.我将它转换为 localhost,所以行结果应该是'bind-address = localhost'。

Otherwise, you should run the your MySQL server with an IP address that existed in the bind-address directive, ie mysql -h 127.0.0.1 .否则,您应该使用存在于 bind-address 指令中的 IP 地址运行 MySQL 服务器,即mysql -h 127.0.0.1

Simple solution on my server: After migrating to a new Debian 7 server with my MySQL databases, the second local IP address , 127.0.1.1 , was missing in my hosts file .我的服务器上的简单解决方案:在使用我的 MySQL 数据库迁移到新的 Debian 7 服务器后,我的hosts 文件中缺少第二个本地 IP 地址127.0.1.1 Adding this resolved the warnings:添加这个解决了警告:

echo -e "\n127.0.1.1       $(hostname)" >> /etc/hosts

In Ubuntu 18:10 Linode 1GB Ram, I experienced this error.在 Ubuntu 18:10 Linode 1GB Ram 中,我遇到了这个错误。 After examining /var/log/mysql/error.log , I came across this:在检查 /var/log/mysql/error.log 之后,我遇到了这个:

[Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. [注意] InnoDB:innodb_empty_free_list_algorithm 已更改为 legacy,因为缓冲池大小较小。 In order to use backoff, increase buffer pool at least up to 20MB.为了使用退避,将缓冲池至少增加到 20MB。

I upgraded my linode to 2GB and restarted mariadb with sudo mysql.我将我的 linode 升级到 2GB 并使用 sudo mysql 重新启动了 mariadb。 Next mysql_secure_admin ran, but the root password did not set for the user-as ususl unitl changing the root user to use the mysql_native_password plugin.接下来 mysql_secure_admin 运行,但没有为用户设置 root 密码-as ususl unitl 将 root 用户更改为使用 mysql_native_password 插件。 Not sure, but it appears that the sock was created, but the server shutdown due to the lack of memory in my VPS.不确定,但似乎创建了 sock,但由于我的 VPS 内存不足,服务器关闭了。

In my case, i had files corrupted in my folder of mysql data就我而言,我的 mysql 数据文件夹中的文件已损坏

mv /var/lib/mysql /var/lib/mysql_old mv /var/lib/mysql /var/lib/mysql_old

so as i had a backup, i moved the directory to "_old", and started the docker again.所以当我有备份时,我将目录移动到“_old”,然后再次启动 docker。 it created a new folder mysql with clean data, and the socket worked.它使用干净的数据创建了一个新文件夹 mysql ,并且套接字工作。

安装 mysql-server 解决了这个问题

sudo apt-get install mysql-server

就我而言,我的问题是我试图从我的 linux 终端访问,而不是从我的带有 mysql 的 docker 容器访问。

If your server/db was working fine and suddenly this issue appear, then just try restarting your db server.如果您的服务器/数据库工作正常并且突然出现此问题,那么只需尝试重新启动您的数据库服务器。 For Centos i do with below command and my issue 'connection refused' 'Cann't connect to local mysql through socket' fixed对于 Centos,我使用以下命令,我的问题 'connection denied' 'Cann't connect to local mysql through socket' 已修复

sudo systemctl start mysqld

I solved this problem by removing this line from my /etc/mysql/my.conf in the mysqld section ([mysqld]):我通过从mysqld部分([mysqld])的/etc/mysql/my.conf中删除此行来解决此问题:

default-character-set=utf8

Restart and it works fine.重新启动,它工作正常。

You should verify the owner of the group for /var/run/mysqld .您应该验证/var/run/mysqld组的所有者。 If it isn't mysql.mysql , then do:如果不是mysql.mysql ,则执行以下操作:

su root
chown mysql.mysql /var/run/mysqld

Upgrading MySQL fixed it for me.升级 MySQL 为我修复了它。 On RHEL-based servers, just run:在基于 RHEL 的服务器上,只需运行:

sudo yum upgrade mysql-server

Did you check if LAMPP is running?您是否检查过 LAMPP 是否正在运行?

sudo bash <path>/lampp start

For me, path is对我来说,路径是

sudo bash /opt/lampp/lampp start

It may be an issue with the configuration file.可能是配置文件的问题。 I had a similar problem, and I couldn't find a solution on the web.我遇到了类似的问题,我在网上找不到解决方案。 I noticed that I had two my.cnf files, one in /etc/mysql and the other in /etc .我注意到我有两个my.cnf文件,一个在/etc/mysql ,另一个在/etc Follow the steps below:请按照以下步骤操作:

  1. Check for my.cnf files on your computer using locate my.cnf .使用locate my.cnf检查计算机上的my.cnf文件。

  2. If there are two entries, ie /etc/my.cnf and /etc/mysql/my.cnf , rename /etc/mysql/my.cnf to something else, eg /etc/mysql/my.cnf.old如果有两个条目,即/etc/my.cnf/etc/mysql/my.cnf ,将/etc/mysql/my.cnf重命名为其他名称,例如/etc/mysql/my.cnf.old

Try to run MySQL again.尝试再次运行 MySQL。

sudo touch /var/lib/mysql/.force_upgrade
sudo rcmysql restart

worked for me when I had this issue当我遇到这个问题时为我工作

I had this on Ubuntu and as I've figured out, there was more than one instance of mysqld.我在 Ubuntu 上有这个,我发现,mysqld 的实例不止一个。

It looked like the previous one had not been completely stopped, while the new one has already started.之前的似乎还没有完全停止,而新的已经开始了。 Running '/etc/init.d/mysql stop' didn't help, it was always returning 'OK' and a new instance has been launched automatically immediately after that:运行“/etc/init.d/mysql stop”没有帮助,它总是返回“OK”,之后立即自动启动一个新实例:

        $ sudo /etc/init.d/mysql stop
         * Stopping MySQL database server mysqld        [ OK ] 
        $ pgrep mysql
        28315
        $ sudo /etc/init.d/mysql stop
         * Stopping MySQL database server mysqld        [ OK ] 
        $ pgrep mysql
        28570
        $ sudo /etc/init.d/mysql stop
         * Stopping MySQL database server mysqld        [ OK ] 
        $ pgrep mysql
        28763
        ..... etc ...

Fortunately, the following command has fixed the problem:幸运的是,下面的命令已经解决了这个问题:

    $ sudo service mysql stop
    mysql stop/waiting

    $ ps -ef | grep mysql
    29841 26858  0 10:59 pts/8    00:00:00 grep --color=auto mysql <--- IT's gone ! 

After that I was able to start mysql again and see that mysql.sock has been successfully created.之后,我能够再次启动 mysql 并看到 mysql.sock 已成功创建。

/etc/mysql/my.cnf中,检查最后一行是:

!includedir /etc/mysql/conf.d/

I was having this problem too and neither of these answers helped me.我也遇到了这个问题,这些答案都没有帮助我。 The issue was different, but the error was the described by the OP.问题有所不同,但错误是由 OP 描述的。

I check the logs of MySQL in /var/log/mysql , and I saw this:我在/var/log/mysql中检查了 MySQL 的日志,我看到了这个:

150309  5:03:19 [ERROR] /usr/sbin/mysqld: unknown variable   'lower_case_tables_names=1'

I opened the /etc/mysql/my.cnf file and outcommented that line # .我打开了/etc/mysql/my.cnf文件并注释掉了该行# After doing that, I was able to connect to the database.之后,我能够连接到数据库。

Honestly I don't know what the problem was.老实说,我不知道问题出在哪里。 The linode server was scheduled to restart due to maintenance, and this error came out of nowhere.由于维护,linode服务器计划重新启动,并且这个错误突然出现。

This error can also occur if you try to change the directory where the database is stored, but imput the wrong directory in the configuration file (like a typo in the second drive as D instead of the accurate D_ ).如果您尝试更改存储数据库的目录,但在配置文件中输入了错误的目录(例如第二个驱动器中的拼写错误为D而不是准确的D_ ),也会发生此错误。 Instead of telling you the typo directory does not exist, it will tell you that you lack permission to access it (leading you to try to change the permissions for the typo directory, which it will let you do).它不会告诉您拼写错误目录不存在,而是告诉您您没有访问它的权限(导致您尝试更改拼写错误目录的权限,它会让您这样做)。 So if you get this error while changing directories, double check the configuration file and make sure you don't have a typo.因此,如果您在更改目录时遇到此错误,请仔细检查配置文件并确保您没有拼写错误。

我不得不说:

sudo /etc/init.d/mysqld start

I my case it was just because mysql was stopped because of the missing /var/log/mysql folder defined in /etc/mysql/my.cnf .我的情况只是因为/etc/mysql/my.cnf中定义的/var/log/mysql文件夹丢失而导致 mysql 停止。 After creating it I could start mysql and it ran as usual.创建它后,我可以启动 mysql 并照常运行。

This answer is likely to drown here, but maybe somebody stumbles upon it accidentally.这个答案很可能在这里被淹没,但也许有人不小心偶然发现了它。

In my case, SELinux prevented the user/application from connecting to the MySQL (MariaDB) server socket.在我的例子中,SELinux 阻止了用户/应用程序连接到 MySQL (MariaDB) 服务器套接字。 On RHEL, check /var/log/audit/audit.log if you have SELinux enabled.在 RHEL 上,检查/var/log/audit/audit.log是否启用了 SELinux。

SOLUTION 1 Purge out (or remove if you want to keep databases) any mysql packages to repeat the installation anew:解决方案 1 清除(如果要保留数据库,则删除)任何 mysql 包以重新重复安装:

sudo apt purge "mysql*"

-Autoremove packages - 自动删除包

sudo apt autoremove

-Stop the apparmor service -停止apparmor服务

sudo systemctl stop apparmor

-Make apparmor drop its profiles (I thought with stop it was enough, but for me it wasn't. With systemctl it doesn't work) - 让 apparmor 删除它的配置文件(我认为 stop 就足够了,但对我来说不是。使用 systemctl 它不起作用)

sudo service apparmor teardown

-Reinstall mysql-server -重新安装mysql服务器

sudo apt install mysql-server

-Install apparmor-utils, to create a profile for mysql in apparmor that allows mysql to run -安装apparmor-utils,在apparmor中为mysql创建一个配置文件,允许mysql运行

sudo apt install apparmor-utils

-Check the status of mysql-server (must be Active(running)) -检查mysql-server的状态(必须是Active(running))

sudo systemctl status mysql

-Generate a profile for mysql in apparmor - 在 apparmor 中为 mysql 生成配置文件

sudo aa-genprof mysql

-In other terminal run mysql (enter root password) - 在其他终端运行mysql(输入root密码)

mysql -u root -p

-do things in MySQL while apparmor is generating the profile in the other terminal - 当 apparmor 在另一个终端中生成配置文件时,在 MySQL 中执行操作

mysql> CREATE DATABASE fooDB mysql> 创建数据库 fooDB

-Swith to the other terminal and press "s" (the prompt tells you it's for "scan") -切换到另一个终端并按“s”(提示告诉你这是“扫描”)

-Say yes to the policies from apparmor you see fit (I guess all of them for mysql), say yes pressing "a" for Allow - 对您认为合适的 apparmor 政策说“是”(我猜它们都适用于 mysql),说“是”按“a”表示允许

-Press "f" to Finish the apparmor profile - 按“f”完成 Apparmor 配置文件

-Restart the apparmor service -重启apparmor服务

sudo systemctl start apparmor

-Check to see if you still can use mysql in the other terminal -检查你是否仍然可以在其他终端使用mysql

mysql>exit mysql>退出

mysql -u root -p

If all is well you can use mysql from the command line.如果一切顺利,您可以从命令行使用 mysql。

In my case I was missing mysql-server.就我而言,我缺少 mysql-server。 So after installing it via sudo apt-get install mysql-server I was able to connect again.因此,通过sudo apt-get install mysql-server后,我能够再次连接。

Another cause of this issue, surprisingly, is the deletion of the folder /var/log/mariadb This was my case after i deleted this log folder.令人惊讶的是,此问题的另一个原因是删除了文件夹 /var/log/mariadb 这是我删除此日志文件夹后的情况。 After the creation, the error disappeared.创建后,错误消失了。

I had previously this problem in Kubuntu 20.04.我以前在 Kubuntu 20.04 中遇到过这个问题。 How It solved for me was to just run:它为我解决的方法是运行:

sudo dpkg --configure -a

The cause was that dpkg had crashed.原因是 dpkg 崩溃了。

I had the problem other time, and I solved it by running:我在其他时间遇到了问题,我通过运行解决了它:

sudo /etc/init.d/mysql start

Think the service was stopped.认为服务已停止。

对我来说,在 CentOS 上,我必须像这样重新启动mariadb服务:

systemctl start mariadb.service

I faced same issue and the problem was that mysql-server was installed but it was not running.我遇到了同样的问题,问题是 mysql-server 已安装但未运行。

Try, service mysql start Or systemctl start mysql试试, service mysql start 或者 systemctl start mysql

When you use localhost<\/code> to connect to MySQL, the operating system uses the socket connector.当您使用localhost<\/code>连接到 MySQL 时,操作系统使用套接字连接器。 However, if you use the 127.0.0.1<\/code> IP address, the operating system will use the TCP\/IP connector.但是,如果您使用127.0.0.1<\/code> IP 地址,操作系统将使用 TCP\/IP 连接器。 So, a possible solution when you're having issues with the socket connector is trying to establish the connection using TCP\/IP by specifying the 127.0.0.1<\/code> IP address instead of localhost<\/code> .因此,当您遇到套接字连接器问题时,一个可能的解决方案是尝试通过指定127.0.0.1<\/code> IP 地址而不是localhost<\/code>来使用 TCP\/IP 建立连接。

"

You can check the logs /var/log/mysql.log您可以检查日志 /var/log/mysql.log

for me it was not working bcs of this error:对我来说,这个错误的 bcs 不起作用:

Cannot allocate memory for the buffer pool error无法为缓冲池错误分配内存

I added this line in /etc/my.cnf and started service:我在 /etc/my.cnf 中添加了这一行并启动了服务:

innodb_buffer_pool_size=100M innodb_buffer_pool_size=100M

This issue happen because MySQL server was not started.出现此问题是因为 MySQL 服务器未启动。 check active status using below command.使用以下命令检查活动状态。

service mysql status

If the active status is stop, then ry starting the MySQL server,如果活动状态为停止,则尝试启动 MySQL 服务器,

service mysql start

I was facing this issue in termux for mariadb, which resolved my issue is these following two lines of command -我在 mariadb 的 termux 中遇到了这个问题,解决了我的问题是以下两行命令 -

pkill mysql

mysqld_safe -u root

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mysql ERROR 2002 (HY000): 无法通过 socket &#39;/var/run/mysqld/mysqld.sock&#39; 连接到本地 MySQL 服务器 (2) - mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 错误2002(HY000):无法通过Vagrant中的套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in Vagrant ERROR 2002(HY000):无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;连接到本地MySQL服务器(111) - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) 错误 2002 (HY000):无法通过套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 错误2002(HY000):无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) occured PDOException SQLSTATE HY000 2002无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;连接到本地MySQL服务器(2) - PDOException SQLSTATE HY000 2002 Can't connect to local MySQL server through socket ' /var/run/mysqld/mysqld.sock' (2) PDOException:SQLSTATE [HY000] [2002]无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;连接到本地MySQL服务器(2) - PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) SQLSTATE [HY000] [2002]无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;连接到本地MySQL服务器(2) - SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 重新启动后无法连接到MySQL服务器:错误2002(HY000):无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器 - Cannot connect to MySQL Server after reboot: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 重新发送mysql密码结果:错误2002(HY000):无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;连接到本地MySQL服务器(2) - Resenting mysql password results: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM