系统重启后MySql数据库恢复到之前的状态

标签 mysql hibernate spring-mvc

我有一个MySql数据库 服务器版本:5.5.47-0ubuntu0.14.04.1(Ubuntu) 以及其中的城市表。

我正在研究 Spring-MVC - hibernate,因此我正在通过 @entity 注释对数据库进行更改。

第一次创建表时,我创建了“名称”列:

CREATE TABLE `City` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  `stateId` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_tr4eopukpxbiked4okmvk3txd` (`stateId`),
  CONSTRAINT `FK_tr4eopukpxbiked4okmvk3txd` FOREIGN KEY (`stateId`) REFERENCES `State` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

几天后,我将“name”列更改为“nameEn”,并添加了“nameLc”列:

CREATE TABLE `City` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nameEn` varchar(45) DEFAULT NULL,
  `nameLc` varchar(45) DEFAULT NULL,
  `stateId` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_tr4eopukpxbiked4okmvk3txd` (`stateId`),
  CONSTRAINT `FK_tr4eopukpxbiked4okmvk3txd` FOREIGN KEY (`stateId`) REFERENCES `State` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

从那天起,每次我重新启动计算机时,此表(以及其他一些具有类似更改的表)都会返回到第一个状态:

CREATE TABLE `City` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  `stateId` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_tr4eopukpxbiked4okmvk3txd` (`stateId`),
  CONSTRAINT `FK_tr4eopukpxbiked4okmvk3txd` FOREIGN KEY (`stateId`) REFERENCES `State` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

重新启动服务时不会出现该错误,仅在重新启动计算机(ubuntu)时才会出现该错误

这是错误日志:

160219  8:59:34 [Note] /usr/sbin/mysqld: Normal shutdown

160219  8:59:34 [Note] Event Scheduler: Purging the queue. 0 events
160219  8:59:34  InnoDB: Starting shutdown...
160219  8:59:36  InnoDB: Shutdown completed; log sequence number 2507506155
160219  8:59:36 [Note] /usr/sbin/mysqld: Shutdown complete

160219  8:59:36 [Note] Plugin 'FEDERATED' is disabled.
160219  8:59:36 InnoDB: The InnoDB memory heap is disabled
160219  8:59:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160219  8:59:36 InnoDB: Compressed tables use zlib 1.2.8
160219  8:59:36 InnoDB: Using Linux native AIO
160219  8:59:36 InnoDB: Initializing buffer pool, size = 128.0M
160219  8:59:36 InnoDB: Completed initialization of buffer pool
160219  8:59:36 InnoDB: highest supported file format is Barracuda.
160219  8:59:36  InnoDB: Waiting for the background threads to start
160219  8:59:37 InnoDB: 5.5.47 started; log sequence number 2507506155
160219  8:59:37 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
160219  8:59:37 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
160219  8:59:37 [Note] Server socket created on IP: '127.0.0.1'.
160219  8:59:37 [Note] Event Scheduler: Loaded 0 events
160219  8:59:37 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.47-0ubuntu0.14.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)
160219  9:09:39 [Note] /usr/sbin/mysqld: Normal shutdown

160219  9:09:39 [Note] Event Scheduler: Purging the queue. 0 events
160219  9:09:39  InnoDB: Starting shutdown...
160219  9:09:41  InnoDB: Shutdown completed; log sequence number 2509266518
160219  9:09:41 [Note] /usr/sbin/mysqld: Shutdown complete

160219  9:09:41 [Note] Plugin 'FEDERATED' is disabled.
160219  9:09:41 InnoDB: The InnoDB memory heap is disabled
160219  9:09:41 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160219  9:09:41 InnoDB: Compressed tables use zlib 1.2.8
160219  9:09:41 InnoDB: Using Linux native AIO
160219  9:09:41 InnoDB: Initializing buffer pool, size = 128.0M
160219  9:09:41 InnoDB: Completed initialization of buffer pool
160219  9:09:41 InnoDB: highest supported file format is Barracuda.
160219  9:09:41  InnoDB: Waiting for the background threads to start
160219  9:09:42 InnoDB: 5.5.47 started; log sequence number 2509266518
160219  9:09:42 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
160219  9:09:42 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
160219  9:09:42 [Note] Server socket created on IP: '127.0.0.1'.
160219  9:09:42 [Note] Event Scheduler: Loaded 0 events
160219  9:09:42 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.47-0ubuntu0.14.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)
160219  9:13:10 [Note] /usr/sbin/mysqld: Normal shutdown

160219  9:13:10 [Note] Event Scheduler: Purging the queue. 0 events
160219  9:13:10  InnoDB: Starting shutdown...
160219  9:13:11  InnoDB: Shutdown completed; log sequence number 2509266518
160219  9:13:11 [Note] /usr/sbin/mysqld: Shutdown complete

160219  9:13:48 [Note] Plugin 'FEDERATED' is disabled.
160219  9:13:48 InnoDB: The InnoDB memory heap is disabled
160219  9:13:48 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160219  9:13:48 InnoDB: Compressed tables use zlib 1.2.8
160219  9:13:48 InnoDB: Using Linux native AIO
160219  9:13:48 InnoDB: Initializing buffer pool, size = 128.0M
160219  9:13:48 InnoDB: Completed initialization of buffer pool
160219  9:13:48 InnoDB: highest supported file format is Barracuda.
160219  9:13:48  InnoDB: Waiting for the background threads to start
160219  9:13:49 InnoDB: 5.5.47 started; log sequence number 2509266518
160219  9:13:49 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
160219  9:13:49 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
160219  9:13:49 [Note] Server socket created on IP: '127.0.0.1'.
160219  9:13:49 [Note] Event Scheduler: Loaded 0 events
160219  9:13:49 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.47-0ubuntu0.14.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

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     = /var/lib/mysql
tmpdir      = /tmp
character_set_server           = utf8                                # If you prefer utf8
collation_server               = utf8_general_ci
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        = 127.0.0.1
#
# * 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_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 = /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



[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/

你能帮我理解并解决这个错误吗?

最佳答案

MySQL 允许您使用现有名称创建临时表。当您尝试创建与现有表同名的表时,MySQL 可能会创建临时表。临时表仅在 session 中可见,因此重新启动计算机后,它将被删除。

如果您想更改现有表,请使用:

ALTER TABLE

关于系统重启后MySql数据库恢复到之前的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35500530/

相关文章:

java - 带注释的 Hibernate 映射 id/长外键到可为空列

java - Spring-MVC RequestMapping URITemplate 中的可选路径变量

java - Spring Mail生成空指针异常

java - 构建java SpringMVC4 Web框架需要什么jar?

PHP $_SESSION 足以保护网页吗?

mysql - 关于分组 2 列的 SQL 选择查询

java - 创建具有数据库权限的新用户

java - 使用复合主键和注释 : 映射多对多

mysql - WordPress Pod : How to only get (sub)categories with articles in it

hibernate - Maven + Hibernate 注释模式生成