mariadb 将系统数据库移动到新位置

mariadb move system database to new location

我刚刚在 Ubuntu 16.04 上安装了 Mariadb 10.1.16,但默认数据目录不合适,因为 space 不足,我需要将其移动到另一个卷。我已将 datadir 条目添加到我的 mysql.cnf 文件中,但是当我尝试加载 mysql 服务时,我得到以下结果:

ago 12 08:27:40 aristotle mysqld[13786]: 2016-08-12  8:27:40 140584295778560 [Note] Plugin 'FEEDBACK' is disabled.
ago 12 08:27:40 aristotle mysqld[13786]: 2016-08-12  8:27:40 140583574173440 [Note] InnoDB: Dumping buffer pool(s) not yet started
ago 12 08:27:40 aristotle mysqld[13786]: 2016-08-12  8:27:40 140584295778560 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
ago 12 08:27:40 aristotle mysqld[13786]: 2016-08-12  8:27:40 140584295778560 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
ago 12 08:27:40 aristotle mysqld[13786]: 2016-08-12  8:27:40 140584295778560 [Note] Server socket created on IP: '::'.
ago 12 08:27:40 aristotle mysqld[13786]: 2016-08-12  8:27:40 140584295778560 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't 
ago 12 08:27:40 aristotle systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
ago 12 08:27:40 aristotle systemd[1]: Failed to start MariaDB database server.
ago 12 08:27:40 aristotle systemd[1]: mariadb.service: Unit entered failed state.
ago 12 08:27:40 aristotle systemd[1]: mariadb.service: Failed with result 'exit-code'.

我的配置文件是:

[client]
# Default is Latin1, if you need UTF-8 set this (also in server section)
default-character-set = utf8 

[mysqld]
#
# * Character sets
# 
# Default is Latin1, if you need UTF-8 set all this (also in client section)
#
character-set-server  = utf8 
collation-server      = utf8_general_ci 
character_set_server   = utf8 
collation_server       = utf8_general_ci
datadir               = /BulkData/Mariadb 

我需要做什么才能将我的数据库放在不同的卷上?

在这种情况下,您有两个选择,增加分区大小 (root),或者只是复制到另一个目录并创建一个 symbolic link。第一个选项似乎更自然,但是,如果你做错了什么可能会危及你的整个系统。第二个是我的选择,因为风险不大,而且比较容易。如果你真的想用第一个,你可以检查这个link:http://www.hiroom2.com/2016/05/19/ubuntu-16-04-extend-and-reduce-lvm-root-filesystem/

如果您想选择第二个选项,您只需:

  • 识别目标分区(很多space),运行命令:df -h

  • 检查目标分区后,停止 MySQL 服务:service mysql stop

  • 移动文件夹(比复制删除要短,而且不用检查权限):mv /var/lib/mysql /usr/lib/mysql

  • 创建符号 link:ln -s /usr/lib/mysql /var/lib/mysql

  • 启动服务:service mysql start