重启服务器时自动删除MySQL数据库表

重启服务器时自动删除MySQL数据库表

我在 Ubuntu 12.04 Server PC 上安装了 LAMP 服务器。我使用 my.cnf 更改了数据库存储位置。更改位置后,它工作正常。但如果我重新启动,我的 MySQL 数据库将被删除,并且我的数据库显示为空。我不知道为什么会发生这种情况,在我将哑数据导入我之前创建的数据库后,它显示以下错误:

CREATE TABLE IF NOT EXISTS  `admin` (

 `usna` VARCHAR( 100 ) NOT NULL ,
 `pas` VARCHAR( 100 ) NOT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;

MySQL said: Documentation

#1146 - Table 'admin_db.admin' doesn't exist

...但如果创建一个新的数据库,然后再次导入数据,它就可以正常工作。我的 my.cnf 文件有误吗?请告诉我如何修复此问题。

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.
[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

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

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[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     = /media/sdc1/Mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
default-storage-engine=InnoDB
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        = 127.0.0.1
#
# * Fine Tuning
#
key_buffer      = 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         = BACKUP
#max_connections        = 100
#table_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
#log_slow_queries   = /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 = /media/sdc1/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



[mysqldump]
quick
quote-names
max_allowed_packet  = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer      = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

答案1

我刚刚遇到了一个与此类似的问题。现在,我不确定这是否能解决您的问题,但它对我有帮助!基本上,我的情况是这样的:当我重新启动 Ubuntu 服务器时,我会进入我的数据库,却发现数据丢失了……尽管我最近刚刚添加了一些数据。所以我对每个表进行了一些挖掘,单击了操作(与顶部的选项卡混合),并注意到一个名为存储引擎的属性。它最初设置为内存,这对我来说似乎不对劲。所以我检查了我的其他数据库,发现它们都设置为 InnoDB。所以我将有问题的数据库中的表更改为 InnoDB,然后重新启动服务器以测试检查它们。数据现在保存起来没有问题!

再次,不确定这是否回答了您的问题,但希望它能够帮助任何在互联网上寻找我所面临的同样问题的解决方案的人。

答案2

我遇到了类似的问题:导入转储没有问题,但在 3 个 Ubuntu 14.04 MySQL 服务器上,数据库在重启后消失。在初始设置期间,我已将 my.cnf 更改为指向新的数据库位置,在 Apparmor 中禁用 MySQL,并使用“sudo /etc/init.d/mysql restart”来更新 MySQL。

问题是 /etc/init.d/mysql 不再正确停止 mysqld——您需要使用“sudo restart mysql”来使用 Upstart 而不是 init。事实证明,所有数据库数据都累积在默认的 /var/lib/mysql 位置中。服务器重新启动后,my.cnf 终于开始首次指向新位置,该位置为空且从未填充。

相关内容