在Ubuntu 16.04服务器上,MySQL启动和重启问题

4

我安装了MySQL 5.7,但后来发现需要MySQL 5.6,因此我使用以下命令删除了所有与MySQL相关的包:

apt-get remove --purge mysql*

所以它被移除了。然后我发布了以下命令:
apt-get install mysql-server-5.6 mysql-client-5.6

所提到的包已安装。 但无论是使用systemctl start mysqlservice mysql start还是重新启动,都无法启动。结果如下:

service mysql restart
or
service mysql start
or
systemctl restart mysql
or
systemctl start mysql

返回:

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

但是
systemctl status mysql

返回

 mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-04-10 13:24:00 EDT; 29s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 15820 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)
 Main PID: 1323 (code=exited, status=0/SUCCESS)

Apr 10 13:23:30 server mysqld[15926]: 2017-04-10 13:23:30 15925 [Note] InnoDB: Compressed tables use zlib 1.2.8
Apr 10 13:23:30 server mysqld[15926]: 2017-04-10 13:23:30 15925 [Note] InnoDB: Using Linux native AIO
Apr 10 13:23:30 server mysqld[15926]: 2017-04-10 13:23:30 15925 [Note] InnoDB: Using CPU crc32 instructions
Apr 10 13:23:30 server mysqld[15926]: 2017-04-10 13:23:30 15925 [Note] InnoDB: Initializing buffer pool, size = 128.0M
Apr 10 13:23:30 server mysqld[15926]: 2017-04-10 13:23:30 15925 [Note] InnoDB: Completed initialization of buffer pool
Apr 10 13:24:00 server mysql[15820]:    ...fail!
Apr 10 13:24:00 server systemd[1]: mysql.service: Control process exited, code=exited status=1
Apr 10 13:24:00 server systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.
Apr 10 13:24:00 server systemd[1]: mysql.service: Unit entered failed state.
Apr 10 13:24:00 server systemd[1]: mysql.service: Failed with result 'exit-code'.

什么是 Failed to start LSB: Start and stop the mysql database server daemon. 在安装5.6版本之前,5.7版本运行良好,但现在出现了这种情况。

/var/log/mysql/errors.log 是空的,这些是 /var/log/syslog 的最后几行。

Apr 10 13:23:30 server mysqld: 2017-04-10 13:23:30 15925 [Note] InnoDB: Completed initialization of buffer pool
Apr 10 13:23:30 server mysqld_safe: mysqld from pid file /var/lib/mysql/server.pid ended
Apr 10 13:24:00 server /etc/init.d/mysql[16277]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Apr 10 13:24:00 server /etc/init.d/mysql[16277]: #007/usr/bin/mysqladmin: connect to server at 'localhost' failed
Apr 10 13:24:00 server /etc/init.d/mysql[16277]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Apr 10 13:24:00 server /etc/init.d/mysql[16277]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Apr 10 13:24:00 server /etc/init.d/mysql[16277]:
Apr 10 13:24:00 server mysql[15820]:    ...fail!
Apr 10 13:24:00 server systemd[1]: mysql.service: Control process exited, code=exited status=1
Apr 10 13:24:00 server systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.
Apr 10 13:24:00 server systemd[1]: mysql.service: Unit entered failed state.
Apr 10 13:24:00 server systemd[1]: mysql.service: Failed with result 'exit-code'.

mysqld_safe 的输出结果

170410 13:33:28 mysqld_safe Logging to syslog.
170410 13:33:28 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
170410 13:33:28 mysqld_safe mysqld from pid file /var/lib/mysql/server.pid ended

这是我的 /etc/mysql/my.cnf,但没有 /etc/my.cnf

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

!includedir /etc/mysql/conf.d/

你能检查一下MySQL进程服务器日志吗?可能在/var/log/mysql/目录下。 - Matt Clark
/var/log/mysql/errors.log是空的。我更新了问题,请再看一下。谢谢。 - mohammad fallah.rasoulnejad
你能检查一下手动启动进程的输出吗?只需运行 mysqld_safe - Matt Clark
170410 13:33:28 mysqld_safe 正在记录到系统日志。 170410 13:33:28 mysqld_safe 从 /var/lib/mysql 数据库启动 mysqld 守护进程。 170410 13:33:28 mysqld_safe 根据 pid 文件 /var/lib/mysql/server.pid,mysqld 进程已结束。 - mohammad fallah.rasoulnejad
2
我认为您仍然在/etc/my.cnf中有一个配置文件,其中包含特定于5.7的参数,现在尝试将其加载到5.6中会导致错误。尝试使用默认配置文件启动。另外,您提出问题才15分钟,放松一下,等待适当的答案。 - Matt Clark
实际上没有 /etc/my.cnf 文件,但我有一个 /etc/mysql/my.cnf 文件。它是一样的吗? - mohammad fallah.rasoulnejad
4个回答

2
当你的/etc/mysql/mysql.conf.d/mysqld.cnf文件设置错误时,就会出现这个问题。如果你最近对这个文件进行了更改,请恢复到以前的版本或将默认版本复制到这里。
    #
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

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

[mysqld]
#
# * Basic Settings
#
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
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 0.0.0.0
#
# * Fine Tuning
#
key_buffer_size     = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
#max_connections        = 100
#table_open_cache       = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#slow_query_log     = 1
#slow_query_log_file    = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id      = 1
#log_bin            = /var/log/mysql/mysql-bin.log
#expire_logs_days   = 10
max_binlog_size   = 100M
#binlog_do_db       = include_database_name
#binlog_ignore_db   = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

0

停止mysql服务:

sudo service mysql stop

移除mysql:

sudo apt-get remove mysql
sudo apt-get purge mysql

然后在终端中发出whereis mysql命令,并使用rm -rf命令删除该命令列出的所有位置。例如:rm -rf /etc/mysql

然后重新安装所需版本的mysql。一切应该正常工作。


我按照你说的做了,但是apt-get remove mysql给我报错,所以我使用了apt-get remove mysql*sudo apt-get purge mysql*。然后在上述命令中找到的目录被删除了,所以我重新安装了它,但是还是一样的。没有改变,也没有启动。 - mohammad fallah.rasoulnejad
执行以下命令,然后尝试启动MySQL:rm -rf /var/run/mysqld/* - coderodour
我按照你说的做了,但是又出现了这个问题:mysql.service任务失败,因为控制进程以错误代码退出。请参阅“systemctl status mysql.service”和“journalctl -xe”获取详细信息。 - mohammad fallah.rasoulnejad
我开始思考,在Ubuntu 16.04上安装MySQL 5.6是否可能? - mohammad fallah.rasoulnejad
让我们在聊天中继续这个讨论 - coderodour
显示剩余2条评论

0

只需检查您的数据库是否已被授予写日志的权限,授予它写日志的权限,问题就会得到解决。


0

1)首先使用以下命令删除已安装的mysql-server-- sudo apt-get remove --purge mysql-server mysql-client mysql-common

2)然后清理所有文件 sudo apt-get autoremove

3)接着安装mysql-server -- sudo apt-get remove -f mysql-server

4)启动mysql服务器-- sudo systemctl start mysql

5)检查mysql-server状态-- systemctl status mysql


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接