2017-09-28 135 views
1

首先,停止與該操作系統啓動時,如果在終端選項卡我運行sudo mysqld(它會立即退出)MySQL服務器實例後,sudo service mysql status在另一個選項卡中的輸出是這樣的:如何在Ubuntu 17.04上更改mysql-server中的root @ localhost密碼?

[email protected]:~$ 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的輸出是不同的:

[email protected]:~$ 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. 

但我想,因爲它the official documentation一節「B.5.3說手動運行sudo mysqld命令。 2.2重置root密碼:Unix和類Unix系統中」我可以通過它的參數--init-file這樣的:

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

更改根MySQL服務器的@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方法更改爲the official documentation link given above解釋root用戶「根」的密碼。

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

[email protected]:~$ 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錯誤,標題中的問題是:我怎麼能在MySQL服務器更改root @本地密碼在Ubuntu 17.04 ?

更新:我用一個新的細節改變了第一段。

更新2:當服務器停止,這是另一種行爲(日期和時間更早從今天開始,而不是從當前時刻):

[email protected]:~$ 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

更新4:/var/log/syslog,我發現這幾行:

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

[email protected]:~$ sudo /etc/init.d/apparmor stop 
[sudo] password for silviu: 
[ ok ] Stopping apparmor (via systemctl): apparmor.service. 

回答

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)。