无法配置或启动MySQL


11

在全新的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中设置了该选项。我试图启动mysqlservice避免--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,并表示没有新的加入到日志中。


当您运行netstat -tlpn时,是否看到MySQL的端口3306?
Craig Efrein

@CraigEfrein:不,未监听端口3306。我什至重新启动系统以查看MySQL是否会在启动时启动,但事实并非如此。
dotancohen

还有--explicit_defaults_for_timestamp,可能的地方,如果您还没有的话。/etc/mysql/my.cnf、/etc/init.d/mysql和/ etc / default / mysql
Craig Efrein 2014年

谢谢。timestamp仅在该字符串中找到了字符串etc/mysql/my.cnf,我已将其注释掉。但是,我仍然在日志中提到它。
dotancohen 2014年

您的主目录中是否存在my.cnf?
Vérace

Answers:


4

您已安装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
  2. 卸载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

谢谢克雷格。我能够重新安装,mysql-server-core-5.5但不能解决问题。我将其添加到问题中。
dotancohen 2014年

@dotancohen,更新了我的答案
Craig Efrein 2014年

谢谢。我完全删除了5.6的痕迹,将/var/lib/mysql和都rm了/var/log/mysql。该mysql_install_db命令失败,因为resolveip找不到。然后mysql-server-5.5,我安装了(显然未与一起安装mysql-server-core-5.5)以获取resolveip。在安装过程中,mysql-server-5.5Unable to set password for the MySQL "root" user再次遇到错误,回到第一个方块!
dotancohen 2014年

@dotancohen更新了答案。这取决于MySQL是否实际在监听。
Craig Efrein 2014年

谢谢。事实上,mysqld_safe死马上:40818 16:52:52 mysqld_safe Logging to '/var/lib/mysql/bruno.err'.140818 16:52:52 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql140818 16:52:54 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
dotancohen 2014年

1

我的my.cnf中有这行

[pol@localhost mysql-5.6.19-linux-x86_64]$ grep expli my.cnf
explicit-defaults-for-timestamp = TRUE

我认为my.cnf参数应使用连字符而不是下划线。


谢谢。您说得对,我也错过了那条线。现在,mysql无法启动,但是什么也没有写到日志中。我将更新问题。
dotancohen 2014年

我知道在Xubuntu(不能站在Unity桌面上!)上,我曾经经历过类似这样的问题。我现在从源代码构建-如果你有兴趣,我会写出来我是怎么做的究竟。经过反复尝试,我从这里改编了我的工作。它比sudo apt-get install xxx还要工作,但至少我知道我的文件在哪里以及如果出现问题了怎么办!
Vérace

谢谢,如果我无法解决这个问题,那么我将尝试您链接的说明。
dotancohen

好吧,那是给那些想通过eclipse编译并运行mysql的人的-我已经将它改编为只想正常运行mysql的人。为什么使用5.5?
Vérace

实际上,我更喜欢5.6,并且不使用eclipse。
dotancohen 2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.