MariaDB是基于二机制包安装的,不需要编译
一、数据磁盘准备
我们在虚拟机上另外挂一块磁盘,大小自己定,这里的是2G的
创建分区
查看新加的磁盘位置
[root@localhost~]# fdisk -l Disk /dev/sda: 137.4 GB, 137438953472 bytes 255 heads, 63 sectors/track, 16709 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: 0x000188e2 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 7859 62914560 8e Linux LVM Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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
我们所用的是lv逻辑卷,所以要选择类型,最要不要忘记保存分区
已创建完成
创建逻辑卷,大小2G提示空间不够,可能是计算方法不一样,就只好使用1.99G了
创建文件系统
[root@localhost~]# mkfs.xfs /dev/myvg/mylv meta-data=/dev/myvg/mylv isize=256 agcount=4, agsize=130560 blks = sectsz=512 attr=2, projid32bit=0 data = bsize=4096 blocks=522240, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
修改/etc/fstab文件实现开机自动挂载
创建挂载目录
[root@localhost~]# mkdir /data
测试自动挂载是否生效
[root@localhost ~]# mount -a [root@localhost ~]# mount /dev/mapper/vg0-root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/vg0-usr on /usr type ext4 (rw) /dev/mapper/vg0-var on /var type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/mapper/myvg-mylv on /data type xfs (rw) //已挂载
创建数据库目录
[root@localhost ~]# mkdir /data/mysql
创建系统用户组mysql,系统用户mysql,并更改/data/mysql/属主属组均为mysql
[root@localhost~]# groupadd -r mysql [root@localhost~]# useradd -r -g mysql -s /sbin/nologin mysql [root@localhost~]# chown -R mysql:mysql /data/
安装MariaDB二进制程序
[root@localhost~]# tar xf mariadb-5.5.36-linux-i686.tar.gz -C /usr/local/ // 解压至安装目录 [root@localhost ~]# cd /usr/local/ [root@localhost local]# ls bin etc games include lib lib64 libexec mariadb-5.5.36-linux-i686 sbin share src [root@localhost local]# ln -sv mariadb-5.5.36-linux-i686/ mysql //创建软链接 `mysql' -> `mariadb-5.5.36-linux-i686/'
配置MariaDB
[root@localhost local]# cd /usr/local/mysql [root@localhost mysql]# scripts/mysql_install_db --user=mysql--datadir=/data/mysql //运行初始化脚本,指明以用户mysql运行,数据库目录为/data/mysql
为MariaDB提供配置文件,并修改此文件中thread_concurrency的值为你的CPU个数乘以2,指定mysql数据库存放数据位置,比如这里使用如下行:
[root@localhost mysql]# cp support-files/my-large.cnf /etc/mysql.cnf
为mysql添加服务脚本
[root@localhost mysql]# cp support-files/mysql.server/etc/rc.d/init.d/mysqld [root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld [root@localhost mysql]# chkconfig --add mysqld
并按照下图修改安装路径、数据路径以及配置文件路径
导出mysql环境变量
[root@localhost ~]# vim /etc/profile.d/mysql.sh
使环境变量生效
[root@localhost mysql]# . /etc/profile.d/mysql.sh
此时配置已经完成了,可以使用服务脚本启动了
启动成功
进入数据库命令行