Linux将MySQL数据库目录挂载至新数据盘

对于Linux系统来说,挂载磁盘的方法其实都大同小异,所以本文以CentOS系统为例,介绍下Linux系统磁盘挂载方法,前面大部分内容源于天翼云的论坛。

1.查看磁盘情况
使用命令fdisk -l # 列出全部磁盘信息

[root@ linuxidc.com ~]# fdisk -l

Disk
/dev/xvda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x0008a9a5

Device Boot          Start        End      Blocks  Id  System
/dev/xvda1              1        523    4194304  82  Linux swap / Solaris
Partition
1 does not end on cylinder boundary.
/dev/xvda2  *        523        5222    37747712  83  Linux

Disk
/dev/xvde: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x00000000


2.创建分区
 fdisk /dev/xvde # 对xvde硬盘进行分区
  n  # 创建一个新分区
  p  # 创建一个主分区(e为扩展分区)
  1  # 1表示第一个主分区
  回车  # 从第1柱面开始分区
  回车  # 表示整个xvde全写入第1分区(若需要将sdb分为多个分区,此时输入+分区大小)
  P  # 查看下已创建好的分区
  w  # 保存并退出

[root@ linuxidc.com ~]# fdisk /dev/xvde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a
new DOS disklabel with disk identifier 0x590ca8b1.
Changes will remain
in memory only, until you decide to write them.
After that, of course, the previous content won
't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It
's strongly recommended to
       
switch off the mode (command 'c') and change display units to
        sectors (command
'u').

Command (m
for help): n
Command action
  e  extended
  p  primary partition (
1-4)
p
Partition number (
1-4): 1
First cylinder (
1-39162, default 1):
Using
default value 1
Last cylinder,
+cylinders or +size{K,M,G} (1-39162, default 39162):
Using
default value 39162

Command (m
for help): p

Disk
/dev/xvde: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x590ca8b1

    Device Boot      Start        End      Blocks  Id  System
/dev/xvde1              1      39162  314568733+  83  Linux

Command (m
for help): w
The partition table has been altered
!

Calling ioctl() to re
-read partition table.
Syncing disks.


3.创建分区文件系统并格式化磁盘
# mkfs.ext4 /dev/xvde1 # 将xvde1以ext4格式进行格式化

[root@ linuxidc.com ~]# mkfs.ext4 xvde1 mke2fs 1.41.12 (17-May-2010) Could not stat xvde1 --- No such file or directory The device apparently does not exist; did you specify it correctly? [root@ linuxidc.com ~]# mkfs.ext4 /dev/xvde1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 19660800 inodes, 78642183 blocks 3932109 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 2400 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 25 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.


4.在home目录下面创建文件夹MySQL,并且将设备挂载至/home/mysql。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/13730.html