Openvz VPS 上“无法为 MySQL“root”用户设置密码”

Openvz VPS 上“无法为 MySQL“root”用户设置密码”

我正在尝试在运行 Ubuntu 13.04 64 位的基于 Openvz 的 VPS 上安装 mysql 服务器,但在安装时不断收到此错误。我尝试了多次,并且重新安装了操作系统,但没有任何变化。如果我尝试设置 root 用户,则会收到错误 2002,如下所示。

我尝试用谷歌搜索该问题,但没有找到类似的东西,你能帮帮我吗?

预先感谢

root@server1:~# apt-get install mysql-server mysql-common mysql-client          Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libdbd-mysql-perl libmysqlclient18 mysql-client-5.5 mysql-server-5.5
Suggested packages:
  tinyca mailx
The following NEW packages will be installed:
  libdbd-mysql-perl libmysqlclient18 mysql-client mysql-client-5.5
  mysql-common mysql-server mysql-server-5.5
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/18.0 MB of archives.
After this operation, 66.9 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Preconfiguring packages ...
 Package configuration
 ──────────────────────────────────────────────────────────────────────────────



┌──────────────────────Configuring mysql-server-5.5─────────────────────────┐
│ While not mandatory, it is highly recommended that you set a password     │
│ for the MySQL administrative "root" user.                                 │
│                                                                           │
│ If this field is left blank, the password will not be changed.            │
│                                                                           │
│ New password for the MySQL "root" user:                                   │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │                                                                       │ │
├─└───────────────────────────────────────────────────────────────────────┘─┤
│                                 <  OK  >                                  │
└───────────────────────────────────────────────────────────────────────────┘







 Package configuration
 ──────────────────────────────────────────────────────────────────────────────





              ┌────────Configuring mysql-server-5.5───────────┐
              │                                               │
              │                                               │
              │ Repeat password for the MySQL "root" user:    │
              │ ┌───────────────────────────────────────────┐ │
              │ │                                           │ │
              ├─└───────────────────────────────────────────┘─┤
              │                   <  OK  >                    │
              └───────────────────────────────────────────────┘







Selecting previously unselected package mysql-common.
(Reading database ... 41054 files and directories currently installed.)
Unpacking mysql-common (from .../mysql-common_5.5.32-0ubuntu0.13.04.1_all.deb) ...
Selecting previously unselected package libmysqlclient18:amd64.
Unpacking libmysqlclient18:amd64 (from .../libmysqlclient18_5.5.32-0ubuntu0.13.04.1_amd64.deb) ...
Selecting previously unselected package libdbd-mysql-perl.
Unpacking libdbd-mysql-perl (from .../libdbd-mysql-perl_4.021-1_amd64.deb) ...
Selecting previously unselected package mysql-client-5.5.
Unpacking mysql-client-5.5 (from .../mysql-client-5.5_5.5.32-0ubuntu0.13.04.1_amd64.deb) ...
Processing triggers for man-db ...
Setting up mysql-common (5.5.32-0ubuntu0.13.04.1) ...
Selecting previously unselected package mysql-server-5.5.
(Reading database ... 41140 files and directories currently installed.)
Unpacking mysql-server-5.5 (from .../mysql-server-5.5_5.5.32-0ubuntu0.13.04.1_amd64.deb) ...
Selecting previously unselected package mysql-client.
Unpacking mysql-client (from .../mysql-client_5.5.32-0ubuntu0.13.04.1_all.deb) ...
Selecting previously unselected package mysql-server.
Unpacking mysql-server (from .../mysql-server_5.5.32-0ubuntu0.13.04.1_all.deb) ...
Processing triggers for man-db ...
Setting up libmysqlclient18:amd64 (5.5.32-0ubuntu0.13.04.1) ...
Setting up libdbd-mysql-perl (4.021-1) ...
Setting up mysql-client-5.5 (5.5.32-0ubuntu0.13.04.1) ...
Setting up mysql-server-5.5 (5.5.32-0ubuntu0.13.04.1) ...
invoke-rc.d: policy-rc.d denied execution of stop.
 Package configuration
 ──────────────────────────────────────────────────────────────────────────────

┌───────────────────────Configuring mysql-server-5.5─────────────────────────┐
│ Unable to set password for the MySQL "root" user                           │
│                                                                            │
│ An error occurred while setting the password for the MySQL                 │
│ administrative user. This may have happened because the account already    │
│ has a password, or because of a communication problem with the MySQL       │
│ server.                                                                    │
│                                                                            │
│ You should check the account's password after the package installation.    │
│                                                                            │
│ Please read the /usr/share/doc/mysql-server-5.5/README.Debian file for     │
│ more information.                                                          │
│                                                                            │
│                                                                            │
├────────────────────────────────────────────────────────────────────────────┤
│                                 <  OK  >                                   │
└────────────────────────────────────────────────────────────────────────────┘



invoke-rc.d: policy-rc.d denied execution of start.
Setting up mysql-client (5.5.32-0ubuntu0.13.04.1) ...
Setting up mysql-server (5.5.32-0ubuntu0.13.04.1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
root@server1:~# sudo mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Enter current password for root (enter for none):

答案1

我遇到了完全相同的问题,结果发现是内存不足的问题。在主机上运行此脚本可以帮我修复此问题:

#!/bin/bash    
cid=104
vzctl set ${cid} --vmguarpages 1024M --save
vzctl set ${cid} --oomguarpages 1024M --save
vzctl set ${cid} --privvmpages 1024M:1024M --save

您可以随意将 1024 更改为您希望容器拥有的任何内存量。您还需要将 104 更改为容器的 ID。

答案2

使用下面的命令来更改mysql服务器的root密码

sudo dpkg-重新配置mysql-server-5.5

答案3

首先检查 mysql 服务器是否确实在运行。以 root 身份运行:

service mysql restart

如果没有发生错误,请继续阅读,否则使用重新安装 mysql 服务器apt-get install --reinstall mysql-server

接下来检查mysql配置文件/etc/mysql/my.cnf并查找以下参数:

user = mysql
...
bind-address = 127.0.0.1

如果需要,请更改它们并重新启动服务器,然后尝试使用以下之一进行连接:

mysql -u root
mysql -u root -p
mysql -u root -p -h localhost
mysql -u root -p -h 127.0.0.1

如果您仍然无法登录,请尝试进行如下更改/etc/apparmor.d/usr.sbin.mysqld

搜索

/var/run/mysqld/mysqld.pid w,
/var/run/mysqld/mysqld.sock w,

用。。。来代替

/{,var/}run/mysqld/mysqld.pid w,
/{,var/}run/mysqld/mysqld.sock w,

重新启动 apparmor 服务service apparmor restart并重试连接到 mysql。如果仍然没有成功,请停止 mysql 服务器并在没有授权表的情况下重新运行它:

sudo service mysql stop
sudo mysqld --skip-grant-tables &

现在你应该能够不用密码登录 mysql ( mysql -u root)。看看你的用户表里发生了什么:

select Host, User, Password from mysql.user;

您应该有 4 个 root 用户,请检查主机名是否正确,并且所有用户都有密码。尝试使用新密码重置密码:

update mysql.user set Password=PASSWORD('YOUR-PASSWORD');
flush privileges;
exit;

现在sudo killall mysqld并重sudo service mysql restart试使用新的凭据进行连接。

答案4

我无法解释为什么会发生这种情况,但在尝试失败后设置 MySQL 的 root 密码以便可能运行的解决方法sudo mysql_secure_installation是运行以下命令:

mysqladmin -u root -p '' password '<new_password>'

*<新密码> = 新密码

相关内容