数据库安装


磁盘规划 (RAID 10 + lvm)
创建RAID10
[root@master ~]# fdisk -l | grep -v lv | grep '^Disk /dev'
Disk /dev/sda: 10.7 GB, 10737418240 bytes
Disk /dev/sdb: 5368 MB, 5368709120 bytes
Disk /dev/sdc: 5368 MB, 5368709120 bytes
Disk /dev/sde: 5368 MB, 5368709120 bytes
Disk /dev/sdd: 5368 MB, 5368709120 bytes
[root@master ~]# yum -y install mdadm
创建两个RAID 1
[root@master ~]# mdadm -C /dev/md0 -l1 -n2 /dev/sdb /dev/sdc
[root@master ~]# mdadm -C /dev/md1 -l1 -n2 /dev/sdd /dev/sde
[root@master ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sde[1] sdd[0]
5241844 blocks super 1.2 [2/2] [UU]
[====>................] resync = 24.7% (1299584/5241844) finish=14.9min speed=4398K/sec
md0 : active raid1 sdc[1] sdb[0]
5241844 blocks super 1.2 [2/2] [UU]
[======>..............] resync = 31.8% (1669696/5241844) finish=13.4min speed=4428K/sec
unused devices: <none>
在RAID 1的基础上创建RAID 0
[root@master ~]# mdadm -C /dev/md10 -l0 -n2 /dev/md[0-1]
[root@master ~]# mdadm -D /dev/md10
/dev/md10:
Version : 1.2
Creation Time : Mon Aug 16 05:13:52 2013
Raid Level : raid0
Array Size : 10480640 (10.00 GiB 10.73 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Mon Aug 16 05:13:52 2013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Name : master:10 (local to host master)
UUID : acb6111a:9df3f58b:6d306d91:e7a15c55
Events : 0
Number Major Minor RaidDevice State
0 9 0 0 active sync /dev/md0
1 9 1 1 active sync /dev/md1
[root@master ~]# mdadm -Ds >> /etc/mdadm.conf
[root@master ~]# cat /etc/mdadm.conf
ARRAY /dev/md0 metadata=1.2 name=master:0 UUID=8612c668:34adfcdd:addd0b44:93cc0e25
ARRAY /dev/md1 metadata=1.2 name=master:1 UUID=8920ce12:68d23fb6:8b2c7e86:b9888922
ARRAY /dev/md10 metadata=1.2 name=master:10 UUID=acb6111a:9df3f58b:6d306d91:e7a15c55
准备挂载目录:
[root@master ~]# mkdir /mydata
LVM
[root@master ~]# vgcreate mydata /dev/md10
No physical volume label read from /dev/md10
Metadata inconsistency: Not all flags successfully exported.
Metadata inconsistency: Not all flags successfully exported.
Writing physical volume data to disk "/dev/md10"
Physical volume "/dev/md10" successfully created
Volume group "mydata" successfully created
[root@master ~]# lvcreate -n mydata -L 5G mydata
Logical volume "mydata" created
格式化文件系统并实现开机自动挂载:
[root@master ~]# mkfs.ext4 /dev/mapper/mydata-mydata
[root@master ~]# blkid /dev/mapper/mydata-mydata
[root@master ~]# vim /etc/fstab
UUID="8512c302-3e7d-47b7-8d69-d51c5253a13d" /mydata ext4 defaults 0 0
[root@master ~]# mount -a
[root@master ~]# ls /mydata/
lost+found
[root@master ~]# df -PTh | grep mydata
/dev/mapper/mydata-mydata ext4 5.0G 138M 4.6G 3% /mydata
二进制安装mysql-5.5.28
[root@master ~]# yum -y install libaio-devel
[root@master ~]# mkdir -pv /mydata/data
#新建用户和组
[root@master ~]# groupadd -r mysql
[root@master ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
[root@master ~]# chown -R mysql:mysql /mydata/data
[root@master ~]# tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local
[root@master ~]# cd /usr/local/
[root@master ~]# ln -sv mysql-5.5.28-linux2.6-i686 mysql
[root@master local]# cd mysql
[root@master mysql]# chown -R mysql:mysql .
[root@master mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mydata/data
[root@master mysql]# chown -R root .
为mysql提供主配置文件:
[root@master mysql]# cp support-files/my-large.cnf /etc/my.cnf
修改配置文件指定数据存放目录datadir = /mydata/data

183934264.png

为mysql提供sysv服务脚本
[root@master mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@master mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@master mysql]# chkconfig --add mysqld
[root@master mysql]# chkconfig mysqld on
[root@master mysql]# ln -sv /usr/local/mysql/bin/mysql /bin/
[root@master mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
输出mysql的库文件给系统库查找路径:
[root@master mysql]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
让系统重新载入系统库:
[root@master mysql]# ldconfig
[root@master ~]# service mysqld start
Starting MySQL... SUCCESS!
[root@master ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.28-log MySQL Community Server (GPL)
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
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> select version();
+------------+
| version() |
+------------+
| 5.5.28-log |
+------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.02 sec)
数据迁移:
[root@master ~]# export PATH=/usr/local/mysql/bin/:$PATH
[root@master mysql]# mysql -e "create database bbs CHARACTER SET GBK;grant all on *.* to root@localhost identified by 'redhat';grant all privileges on bbs.* to root@'172.16.100.%' identified by 'redhat';delete from mysql.user where password = '';flush privileges"
[root@web1 ~]# mysqldump -uroot -p bbs | mysql -uroot -predhat bbs
[root@web1 ~]# sed -i 's/localhost/172\.16\.100\.61/g' /var/www/html/config/config_global.php
[root@web2 ~]# sed -i 's/localhost/172\.16\.100\.61/g' /var/www/html/config/config_global.php

183934212.png

mysql> show processlist;
+----+----------------------+---------------------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+----------------------+---------------------+------+---------+------+-------+------------------+
| 8 | root | localhost | NULL | Query | 0 | NULL | show processlist |
| 9 | unauthenticated user | 172.16.100.81:52901 | NULL | Connect | NULL | login | NULL |
+----+----------------------+---------------------+------+---------+------+-------+------------------+

[root@web3 ~]# sed -i 's/localhost/172\.16\.100\.61/g' /usr/local/apache/htdocs/data/config.php
[root@master mysql]# mysql -p -e "create database shop;grant all on shop.* to shopdba@'172.16.100.%' identified by 'redhat';flush privileges;"
[root@web3 ~]# mysqldump shop >shop.sql
[root@web3 ~]# scp shop.sql 172.16.100.61:/root/
[root@master ~]# mysql -p shop<shop.sql

183934878.png

mysql> show processlist;
+----+----------------------+---------------------+------+---------+------+-------+------------------+
| Id | User                 | Host                | db   | Command | Time | State | Info             |
+----+----------------------+---------------------+------+---------+------+-------+------------------+
| 31 | root                 | localhost           | NULL | Query   |    0 | NULL  | show processlist |
| 35 | unauthenticated user | 172.16.100.42:38781 | NULL | Connect | NULL | login | NULL             |
+----+----------------------+---------------------+------+---------+------+-------+------------------+


你可能感兴趣的:(mysq,数据库安装)