Mysql-5.5

無法配置或啟動 MySQL

  • March 21, 2019

在全新的 Kubuntu 14.04 安裝上,我執行了sudo aptitude install mysql-server-core-5.6. 由於某些 KDE 軟體包對 的依賴,安裝無法完成,mysql-server-core-5.5這些軟體包將被替換。現在,當我執行時sudo aptitude install mysql-server-5.5,指定密碼後出現此錯誤:

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.

我實際上已經閱讀過/usr/share/doc/mysql-server-5.5/README.Debian,但與我的情況無關。MySQL 日誌有助於:

$ tail /var/log/mysql/error.log 
140818 10:17:16 InnoDB: Completed initialization of buffer pool
140818 10:17:16 InnoDB: highest supported file format is Barracuda.
140818 10:17:16  InnoDB: Waiting for the background threads to start
140818 10:17:17 InnoDB: 5.5.38 started; log sequence number 1595675
140818 10:17:17 [ERROR] /usr/sbin/mysqld: unknown option '--explicit_defaults_for_timestamp'
140818 10:17:17 [ERROR] Aborting

140818 10:17:17  InnoDB: Starting shutdown...
140818 10:17:18  InnoDB: Shutdown completed; log sequence number 1595675
140818 10:17:18 [Note]

但是我找不到在哪個腳本--explicit_defaults_for_timestamp中設置了該選項。我試圖在mysql沒有service避免該--explicit_defaults_for_timestamp選項的情況下啟動,但它仍然無法啟動:

$ ps aux | grep mysql
dotanco+ 25458  0.0  0.0  11748   928 pts/4    S+   10:30   0:00 grep --color=auto mysql

$ sudo mysqld_safe --skip-grant-tables &
[1] 25470
140818 10:30:54 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
140818 10:30:54 mysqld_safe Logging to '/var/log/mysql/error.log'.
140818 10:30:54 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140818 10:30:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]+  Done                    sudo mysqld_safe --skip-grant-tables

$ ps aux | grep mysql
dotanco+ 25810  0.0  0.0  11748   932 pts/4    S+   10:31   0:00 grep --color=auto mysql

錯誤告訴我Remove all --log-error configuration options。因此,我編輯/etc/mysql/my.cnf並註釋掉了以下行:

log-error  = /var/log/mysql/error.log

現在我沒有收到錯誤但仍然無法登錄:

$ sudo mysqld_safe --skip-grant-tables &
[1] 26558
140818 10:34:37 mysqld_safe Logging to syslog.
140818 10:34:38 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140818 10:34:40 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]+  Done                    sudo mysqld_safe --skip-grant-tables

$ mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

**可能是什麼問題?**我應該如何進行?

編輯

我現在已經註釋掉explicit-defaults-for-timestampmy.cnf. 這是整個文件,減去標題註釋:

$ cat /etc/mysql/my.cnf 

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
#explicit_defaults_for_timestamp

bind-address    = 127.0.0.1

#log-error      = /var/log/mysql/error.log

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

symbolic-links=0

!includedir /etc/mysql/conf.d/

這是我嘗試執行 MySQL 時發生的情況:

$ sudo echo 1 >> /var/log/mysql/error.log

$ tail /var/log/mysql/error.log 
140818 10:31:49  InnoDB: Waiting for the background threads to start
140818 10:31:50 InnoDB: 5.5.38 started; log sequence number 1595675
140818 10:31:50 [ERROR] /usr/sbin/mysqld: unknown option '--explicit_defaults_for_timestamp'
140818 10:31:50 [ERROR] Aborting

140818 10:31:50  InnoDB: Starting shutdown...
140818 10:31:51  InnoDB: Shutdown completed; log sequence number 1595675
140818 10:31:51 [Note] 
140818 10:31:51 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
1

$ sudo service mysql start
start: Job failed to start

$ tail /var/log/mysql/error.log 
140818 10:31:49  InnoDB: Waiting for the background threads to start
140818 10:31:50 InnoDB: 5.5.38 started; log sequence number 1595675
140818 10:31:50 [ERROR] /usr/sbin/mysqld: unknown option '--explicit_defaults_for_timestamp'
140818 10:31:50 [ERROR] Aborting

140818 10:31:50  InnoDB: Starting shutdown...
140818 10:31:51  InnoDB: Shutdown completed; log sequence number 1595675
140818 10:31:51 [Note] 
140818 10:31:51 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
1

$ grep explicit_defaults_for_timestamp /etc/mysql/my.cnf /etc/init.d/mysql /etc/default/mysql
/etc/mysql/my.cnf:#explicit_defaults_for_timestamp
grep: /etc/default/mysql: No such file or directory

可以看出,日誌中沒有寫入任何新內容,explicit_defaults_for_timestamp也沒有在任何地方設置該選項。

我能夠重新安裝mysql-server-core-5.5,但這並沒有解決問題:

$ sudo aptitude reinstall mysql-server-core-5.5
The following packages will be REINSTALLED:
 mysql-server-core-5.5 
0 packages upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 3,213 kB of archives. After unpacking 0 B will be used.
Get: 1 http://il.archive.ubuntu.com/ubuntu/ trusty-updates/main mysql-server-core-5.5 amd64 5.5.38-0ubuntu0.14.04.1 [3,213 kB]
Fetched 3,213 kB in 1s (3,163 kB/s)                
(Reading database ... 217167 files and directories currently installed.)
Preparing to unpack .../mysql-server-core-5.5_5.5.38-0ubuntu0.14.04.1_amd64.deb ...
Unpacking mysql-server-core-5.5 (5.5.38-0ubuntu0.14.04.1) over (5.5.38-0ubuntu0.14.04.1) ...
Replaced by files in installed package mysql-common (5.6.20-1ubuntu14.04) ...
Processing triggers for man-db (2.6.7.1-1) ...
Setting up mysql-server-core-5.5 (5.5.38-0ubuntu0.14.04.1) ...

$ sudo service mysql status
mysql stop/waiting

$ sudo service mysql start
start: Job failed to start

$ tail /var/log/mysql/error.log 
140818 10:31:49  InnoDB: Waiting for the background threads to start
140818 10:31:50 InnoDB: 5.5.38 started; log sequence number 1595675
140818 10:31:50 [ERROR] /usr/sbin/mysqld: unknown option '--explicit_defaults_for_timestamp'
140818 10:31:50 [ERROR] Aborting

140818 10:31:50  InnoDB: Starting shutdown...
140818 10:31:51  InnoDB: Shutdown completed; log sequence number 1595675
140818 10:31:51 [Note] 
140818 10:31:51 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
1

1日誌最後一行的那個是之前添加的,表示日誌中echo沒有添加任何新內容。

您安裝了mysql-server-core-5.6,其中部分失敗或部分安裝。

-explicit_defaults_for_timestamp僅適用於 MySQL 5.6 。可能是部分安裝mysql-server-core-5.6添加了此選項。我現在建議您刪除任何痕跡mysql-server-core-5.6並重新初始化數據目錄。

  1. 殺死任何正在執行的 mysqld 程序:
ps aux | grep mysql
kill pid
  1. 解除安裝mysql-server-core-5.6軟體包:
apt-get remove mysql-server-core-5.6

文件列表在這裡 3. 重新初始化數據庫目錄:

一種。rm -Rf /var/lib/mysql/*

B.mysql_install_db /var/lib/mysql 4. 註釋掉裡面的!includedir /etc/mysql/conf.d/選項my.cnf


殺死任何現有的 MySQL 程序,然後使用該skip-grant-tables選項啟動 MySQL。

A. 獲取 mysqld 守護程序的準確路徑:

which mysqld_safe

B. 在沒有授權表的情況下執行 MySQL:

/mysqld_safe_directory/mysqld_safe --skip-grant-tables &
ex /bin/mysqld_safe

C. 確保 mysql 正在監聽:

netstat -tlpn 

您應該看到埠 3306。

D. 如果是,登錄 MySQL:

mysql -u root -h 127.0.0.1

E. 設置新密碼:

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

引用自:https://dba.stackexchange.com/questions/74227