如何在Ubuntu 17.04上更改mysql-server中的root @ localhost密码?

时间:2017-09-28 08:48:37

标签: mysql linux ubuntu ubuntu-17.04

首先,在停止以OS开头的MySQL服务器实例后,如果在终端选项卡中我运行sudo mysqld(它会立即退出),则另一个选项卡中的sudo service mysql status输出为:

silviu@silviu-Inspiron-3537:~$ sudo service mysql status
[sudo] password for silviu: 
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2017-09-28 00:33:25 EEST; 10h ago
 Main PID: 6157 (code=exited, status=0/SUCCESS)

sep 28 00:33:03 silviu-Inspiron-3537 systemd[1]: Starting MySQL Community Server...
sep 28 00:33:04 silviu-Inspiron-3537 systemd[1]: Started MySQL Community Server.
sep 28 00:33:23 silviu-Inspiron-3537 systemd[1]: Stopping MySQL Community Server...
sep 28 00:33:25 silviu-Inspiron-3537 systemd[1]: Stopped MySQL Community Server.

我删除了/var/log/syslog,并且在执行上述步骤后,不会使用新内容重新创建此日志文件。在/var/log/mysql/error.log中,上述命令没有附加新行。

如果我运行sudo service mysql start而不是sudo mysqld,则命令sudo service mysql status的输出会有所不同:

silviu@silviu-Inspiron-3537:~$ sudo service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2017-09-28 11:19:24 EEST; 7s ago
  Process: 16133 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 16124 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 16132 (mysqld)
    Tasks: 28 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─16132 /usr/sbin/mysqld

sep 28 11:19:23 silviu-Inspiron-3537 systemd[1]: Starting MySQL Community Server...
sep 28 11:19:24 silviu-Inspiron-3537 systemd[1]: Started MySQL Community Server.

但我想手动运行sudo mysqld命令,因为在the official documentation中它在“B.5.3.2.2重置root密码:Unix和类Unix系统”一节中说明了我可以通过它的参数--init-file就像这样:

sudo mysqld --init-file=/home/silviu/Desktop/chpass.sql

更改MySQL服务器的root @ localhost密码。 chpass.sql的当前内容为:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
UPDATE mysql.user
    SET authentication_string = PASSWORD('root'), password_expired = 'N'
    WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

我在这个文件中编译了所有三种SQL方法,将root用户的密码更改为“root”,如the official documentation link given above中所述。

我使用官方5.7.19-0ubuntu0.17.04.1包的mysql-server版本:

silviu@silviu-Inspiron-3537:~$ sudo apt-cache policy mysql-server
mysql-server:
  Instalat:   5.7.19-0ubuntu0.17.04.1
  Candidează: 5.7.19-0ubuntu0.17.04.1
  Tabela de versiuni:
 *** 5.7.19-0ubuntu0.17.04.1 500
        500 http://ro.archive.ubuntu.com/ubuntu zesty-updates/main amd64 Packages
        500 http://ro.archive.ubuntu.com/ubuntu zesty-updates/main i386 Packages
        500 http://security.ubuntu.com/ubuntu zesty-security/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu zesty-security/main i386 Packages
        100 /var/lib/dpkg/status
     5.7.17-0ubuntu1 500
        500 http://ro.archive.ubuntu.com/ubuntu zesty/main amd64 Packages
        500 http://ro.archive.ubuntu.com/ubuntu zesty/main i386 Packages

对于这个sudo mysqld错误,标题中的问题仍然存在:如何在Ubuntu 17.04上更改mysql-server中的root @ localhost密码?

更新:我用新的细节更改了第一段。

更新2:当服务器停止时,这是另一种行为(日期和时间是从今天开始,而不是从当前时刻开始):

silviu@silviu-Inspiron-3537:~$ sudo mysqld_safe --skip-grant-tables
2017-09-28T09:39:41.881058Z mysqld_safe Logging to syslog.
2017-09-28T09:39:41.883753Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-09-28T09:39:41.886446Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

更新3: a relevant related question on AskUbuntu

/var/log/syslog中的

更新4:我找到了这些行:

Sep 28 12:58:09 silviu-Inspiron-3537 kernel: [ 4571.559077] audit: type=1400 audit(1506592689.673:93): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/8532/status" pid=8532 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Sep 28 12:58:09 silviu-Inspiron-3537 kernel: [ 4571.559079] audit: type=1400 audit(1506592689.673:94): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=8532 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Sep 28 12:58:09 silviu-Inspiron-3537 kernel: [ 4571.559148] audit: type=1400 audit(1506592689.673:95): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/8532/status" pid=8532 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

/etc/apparmor.d/usr.sbin.mysqld我尝试添加这些行:

/proc/** rwk
/sys/devices/system/** rwk

但是,即使我使用此命令禁用AppArmor,然后再次运行sudo mysqld,也会出现相同的错误:

silviu@silviu-Inspiron-3537:~$ sudo /etc/init.d/apparmor stop
[sudo] password for silviu: 
[ ok ] Stopping apparmor (via systemctl): apparmor.service.

1 个答案:

答案 0 :(得分:0)

我设法使用信息from this AskUbuntu answer

解决了这个问题
  

如果它没有帮助使用:

sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-5.5
sudo apt-get install mysql-server
     

完全删除你的mysql并重新安装警告:如果你有任何数据库,他们将被删除问候,ADDB

而不是5.5我使用5.7(使用apt的最新版本)。