CentOS中开启mysql挂载

挂载的作用其实说白了就是备份。防止数据库文件损害或者数据库被误删导致数据丢失。

创建一个文件名为my.cnf内容如下

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
default_authentication_plugin=mysql_native_password

# Custom config should go here
!includedir /etc/mysql/conf.d/

server-id=200

如果已经安装了mysql需要对mysql容器进行卸载。

卸载后在自己准备保存挂载数据的地方创建目录结构如下,并将my.cnf放置到conf文件夹中

创建好之后重安装mysql的容器

创建一个名为mysql的容器,并且配置相关信息。把自己的目录位置替换到下面的我的目录位置中

docker run -it \
--name mysql \
-p 3306:3306 \
--privileged \
-e MYSQL_ROOT_PASSWORD=123 \
-v /etc/localtime:/etc/localtime \
-v /usr/local/software/mysql/3306/conf/my.cnf:/etc/mysql/my.cnf \
-v /usr/local/software/mysql/3306/data:/var/lib/mysql \
-v /usr/local/software/mysql/3306/mysql-files:/var/lib/mysql-files \
-d mysql

创建成功后log一下,发现已经成功了。

还要确认是否挂载成功。

开启mysql服务后

使用windows里的navicat连接到CentOS里的数据库。上篇文章有写如何连接的。

CentOS使用docker安装mysql并使用navicat 远程链接-CSDN博客

并且创建数据库和表

创建完成后在CentOS中进行访问

访问成功而且有数据

这时候打开自己之前创建用于保存挂载数据的位置查看是否有新建的库和表的信息

打开后发现已经自动开启挂载了。有库和表的备份信息了。

相关推荐

  1. 华纳云:centos7的nfs开机自动挂载怎么实现?

    2024-01-07 11:24:03       34 阅读
  2. CentOS 磁盘挂载

    2024-01-07 11:24:03       10 阅读
  3. CentOS 7挂载命令详解

    2024-01-07 11:24:03       12 阅读
  4. CentOS 8 安装与配置 MySQL

    2024-01-07 11:24:03       19 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-07 11:24:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-07 11:24:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-07 11:24:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-07 11:24:03       18 阅读

热门阅读

  1. uView Tabbar 底部导航栏

    2024-01-07 11:24:03       43 阅读
  2. 人工智能(AI)会如何改变我们的工作和生活

    2024-01-07 11:24:03       34 阅读
  3. jQuery文件下载方法及引入HTML语法

    2024-01-07 11:24:03       35 阅读
  4. 企业如何实现合理定岗定编?

    2024-01-07 11:24:03       34 阅读
  5. Centos 7 安装 ffmpeg

    2024-01-07 11:24:03       41 阅读
  6. 【华为OD真题 Python】石头剪刀布游戏

    2024-01-07 11:24:03       39 阅读
  7. MySQL 8.0中新增的功能(三)

    2024-01-07 11:24:03       38 阅读
  8. SQL Server 中 RAISERROR 的用法详解

    2024-01-07 11:24:03       33 阅读