首页 > 数据库 >mysql实现数据文件存储到指定分区

mysql实现数据文件存储到指定分区

时间:2024-01-10 23:00:59浏览次数:41  
标签:数据文件 -- 分区 Jan mysqld mysql node1 root

通过rpm安装的mysql默认程序文件放在/usr/bin,数据文件放在/var/lib/mysql,需要将数据文件放在不同分区,保证数据量时将根目录撑爆

一、关闭数据库

[root@node1 bin]# systemctl stop mysqld
[root@node1 bin]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Wed 2024-01-10 22:23:45 CST; 16s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 103618 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 103590 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 103621 (code=exited, status=0/SUCCESS)

Jan 06 23:37:04 node1 systemd[1]: Starting MySQL Server...
Jan 06 23:37:05 node1 systemd[1]: Started MySQL Server.
Jan 10 22:23:41 node1 systemd[1]: Stopping MySQL Server...
Jan 10 22:23:45 node1 systemd[1]: Stopped MySQL Server.

二、将数据文件放到其它分区

[root@node1 bin]# cd /home/
[root@node1 home]# mkdir mysqldata
[root@node1 home]# cp -a /var/lib/mysql /home/mysqldata/
[root@node1 home]# cd mysqldata/
[root@node1 mysqldata]# ls
mysql
[root@node1 mysqldata]# ll
total 4
drwxr-x--x 7 mysql mysql 4096 Jan 10 22:23 mysql
[root@node1 mysqldata]# cd mysql/
[root@node1 mysql]# ll
total 176252
drwxr-x--- 2 mysql mysql       20 Jan  6 23:39 12233
-rw-r----- 1 mysql mysql       56 Jan  6 15:33 auto.cnf
-rw------- 1 mysql mysql     1680 Jan  6 15:33 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 Jan  6 15:33 ca.pem
-rw-r--r-- 1 mysql mysql     1112 Jan  6 15:33 client-cert.pem
-rw------- 1 mysql mysql     1680 Jan  6 15:33 client-key.pem
-rw-r----- 1 mysql mysql      790 Jan 10 22:23 ib_buffer_pool
-rw-r----- 1 mysql mysql 79691776 Jan 10 22:23 ibdata1
-rw-r----- 1 mysql mysql 50331648 Jan 10 22:23 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Jan  6 15:33 ib_logfile1
drwxr-x--- 2 mysql mysql    40960 Jan  6 16:36 ivsom
drwxr-x--- 2 mysql mysql     4096 Jan  6 15:33 mysql
drwxr-x--- 2 mysql mysql     8192 Jan  6 15:33 performance_schema
-rw------- 1 mysql mysql     1680 Jan  6 15:33 private_key.pem
-rw-r--r-- 1 mysql mysql      452 Jan  6 15:33 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 Jan  6 15:33 server-cert.pem
-rw------- 1 mysql mysql     1680 Jan  6 15:33 server-key.pem
drwxr-x--- 2 mysql mysql     8192 Jan  6 15:33 sys

三、修改配置文件

原来配置文件

[root@node1 mysql]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
user=root
datadir=/var/lib/mysql   //数据文件目录
socket=/var/lib/mysql/mysql.sock   //sock目录
lower_case_table_names=1
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

修改后的配置文件

[root@node1 mysql]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
user=root
datadir=/home/mysqldata/mysql
socket=/home/mysqldata/mysql/mysql.sock
lower_case_table_names=1
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
default-character-set=utf8
socket=/home/mysqldata/mysql/mysql.sock

[mysql]
default-character-set=utf8
socket=/home/mysqldata/mysql/mysql.sock

四、启动数据库

[root@node1 mysql]# systemctl start mysqld
[root@node1 mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2024-01-10 22:42:29 CST; 12s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 126422 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 126385 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 126425 (mysqld)
    Tasks: 27
   Memory: 191.0M
   CGroup: /system.slice/mysqld.service
           └─126425 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Jan 10 22:42:27 node1 systemd[1]: Starting MySQL Server...
Jan 10 22:42:29 node1 systemd[1]: Started MySQL Server.

五、验证数据文件更新分区是否成功

[root@node1 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW VARIABLES LIKE 'datadir';
+---------------+------------------------+
| Variable_name | Value                  |
+---------------+------------------------+
| datadir       | /home/mysqldata/mysql/ |  //确实已经更新
+---------------+------------------------+
1 row in set (0.05 sec)

mysql>

标签:数据文件,--,分区,Jan,mysqld,mysql,node1,root
From: https://blog.51cto.com/u_1969518/9187027

相关文章

  • MySQL InnoDB ReplicaSet安装文档
    MySQL副本集介绍MySQLInnoDBReplicaSet(也叫MySQL副本集,有些地方也翻译成MySQL复制集)是在MySQL8.0.19版本(2020-01-13Released)之后开始支持的,MySQL副本集中拥有一个primary节点,一个或多个secondary节点,它不像MySQLInnoDBCluster一样提供故障自愈和多主模式,但是它提供手......
  • MySQL Ignoring the redo log due to missing MLOG_CHECKPOINT between the checkpoin
    错误信息:2023-12-12T09:32:31.383149Z0[ERROR]InnoDB:IgnoringtheredologduetomissingMLOG_CHECKPOINTbetweenthecheckpoint5777611209andtheend5777612857.2023-12-12T09:32:31.384149Z0[ERROR]InnoDB:PlugininitializationabortedwitherrorGeneri......
  • 揭秘MySQL中的"黑洞":为什么你应避免默认使用NULL值?
    摘要:在MySQL中,NULL值是一种特殊的标记,表示数据缺失或未知。然而,默认使用NULL值可能会引发一系列问题。本文将深入探讨为什么不建议默认使用NULL值,并通过具体示例揭示其潜在风险。一、什么是NULL值?在MySQL中,NULL表示一个字段没有值或数据未知。不同于空字符串("")或0,NULL表示缺失或......
  • Linux安装MySQL5.7并设置systemd方式管理
    1、安装前检查1)检查linux系统是否安装过mysql#检查系统中有无安装过mysql,如果有就卸载rpm-qa|grepmysqlrpm-e--nodepsmysql-xxxx#检查所有mysql对应的文件夹,全部删除whereismysqlfind/-namemysqlrm-rf......#删除mysql的配置文件rm-rf/etc/my.cnf#删......
  • MySQL运维实战(2.4) SSL认证在MySQL中的应用
    作者:俊达引言MySQL支持使用TLS协议进行通信,该协议在数据库通信中具有关键作用。首先,TLS能够加密客户端与服务端之间的通信数据,涵盖了客户端发送至服务端的SQL请求以及服务端返回给客户端的数据,从而确保敏感信息的保密性和完整性。除此之外,TLS还允许客户端验证服务端的身份,确保安......
  • win11安装mysql(解压版)
    一、官网下载https://dev.mysql.com/downloads/mysql/二、配置环境变量设置>系统>系统信息>高级系统设置三、配置my.inimysql根目录下创建my.ini1[mysqld]2;设置3306端口3port=33064;设置mysql的安装目录5basedir=D:\\XX\\mysql-8.0.18-winx646;设置my......
  • Go Gin+MySQL实现增删改查
    一、概述使用Gin框架+MySQL数据库实现增删改查(原生sql)实现步骤:1.导入Gin框架goget-ugithub.com/gin-gonic/gin2.引入MySQL驱动goget-ugithub.com/go-sql-driver/mysql3.注册Gin路由//注册用户路由funcRegisterUser(){......
  • MySql 中 INSTR() 用法
    在MySQL中,INSTR()函数用于查找一个字符串中是否包含另一个指定的子串,并返回该子串在原始字符串中第一次出现的位置。以下是INSTR()函数的语法:INSTR(str,substr)其中,str是要搜索的目标字符串;substr是要查找的子字符串。如果str包含substr,则返回substr在str中第一......
  • MySql 中 SUBSTRING_INDEX()用法
    SUBSTRING_INDEX()函数用于从一个指定分隔符分隔的字符串中提取子串。它返回一个字符串,包含在原始字符串中出现在指定分隔符之前或之后的所有字符。以下是SUBSTRING_INDEX()函数的语法:SUBSTRING_INDEX(str,delim,count)其中,str是要分割的字符串;delim是指定的分隔符;count......
  • centos安装mysql8,银河麒麟安装mysql8,arm(aarch)架构,rpm包,完全离线安装
    作者主页:https://www.cnblogs.com/milkbox/参考:软件包下载:https://rpmfind.net/linux/rpm2html/search.phpMySQL::DownloadMySQLCommunityServer主要教程:十二、MySQL8.0.32离线安装(适用于Linux-CentOS7)_linux离线安装libaio-CSDN博客本教程以银河麒麟v10为例注......