首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >‘无法为Openvz上的MySQL "root“用户设置密码

问‘无法为Openvz上的MySQL "root“用户设置密码
EN

Ask Ubuntu用户
提问于 2013-08-27 15:27:50
回答 2查看 18.5K关注 0票数 5

我试图在我的基于Openvz的VPS上安装mysql服务器,运行Ubuntu13.04 64位,在安装时我一直收到这个错误。我尝试了多次,我也重新安装了操作系统,没有任何改变。如果我试图在收到错误2002之后设置根用户,如下所示。

我试着搜索这个问题,但是我没有找到这样的东西,你能帮我吗?

提前感谢

代码语言:javascript
复制
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):
EN

回答 2

Ask Ubuntu用户

发布于 2015-03-24 07:11:29

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

sudo dpkg-重新配置mysql-服务器-5.5

票数 1
EN

Ask Ubuntu用户

发布于 2013-08-28 08:19:49

首先,检查mysql服务器是否真的在滚动。作为根运行:

代码语言:javascript
复制
service mysql restart

如果没有出现错误,继续读取,否则用apt-get install --reinstall mysql-server重新安装mysql服务器。

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

代码语言:javascript
复制
user = mysql
...
bind-address = 127.0.0.1

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

代码语言:javascript
复制
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:

搜索

代码语言:javascript
复制
/var/run/mysqld/mysqld.pid w,
/var/run/mysqld/mysqld.sock w,

代之以

代码语言:javascript
复制
/{,var/}run/mysqld/mysqld.pid w,
/{,var/}run/mysqld/mysqld.sock w,

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

代码语言:javascript
复制
sudo service mysql stop
sudo mysqld --skip-grant-tables &

现在,您应该可以在没有密码(mysql -u root)的情况下登录mysql。查看一下您的用户表上发生了什么:

代码语言:javascript
复制
select Host, User, Password from mysql.user;

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

代码语言:javascript
复制
update mysql.user set Password=PASSWORD('YOUR-PASSWORD');
flush privileges;
exit;

现在,sudo killall mysqld和sudo service mysql restart重新尝试连接新的凭据。

票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/337934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档