【问题标题】:ubuntu - mysql start and restart issue on ubuntu 16.04 serverubuntu - ubuntu 16.04 服务器上的 mysql 启动和重启问题
【发布时间】:2020-05-27 03:45:22
【问题描述】:

我安装了 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/
  • /var/log/mysql/errors.log 为空。我更新了问题,请再看看。谢谢
  • 你能检查手动启动进程的输出吗?只需运行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/my.cnf 中仍有一个配置文件,其中包含特定于 5.7 的参数,现在尝试将其加载到 5.6 会导致错误。尝试使用默认配置文件启动。此外,距离您提出问题仅 15 分钟,放松,等待正确答案。

标签: mysql ubuntu-16.04


【解决方案1】:

当您的 /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

【讨论】:

    【解决方案2】:

    停止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*。并删除了上述命令中找到的目录,因此重新安装了它,但它的钢一样。没有变化,也没有开始
    • 这是您完整的mysql.cnf 文件吗?
    • 发出这个命令然后尝试启动mysql rm -rf /var/run/mysqld/*
    • 我照你说的做了蚂蚁,这又发生了:Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
    • 我开始思考是否可以在ubuntu 16.04中安装mysql 5.6?
    【解决方案3】:

    只需检查您的数据库是否已被授予写入日志的权限,并授予它写入日志的权限,这将得到解决。

    【讨论】:

      【解决方案4】:

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

      2)然后清理所有文件 sudo apt-get 自动删除

      3)然后安装mysql-server -- sudo apt-get remove -f mysql-server

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-15
        • 2017-08-31
        • 2016-11-27
        • 2017-03-17
        • 1970-01-01
        • 2017-09-01
        相关资源
        最近更新 更多