一、环境介绍
操作系统:Redhat5.8_64bit
MySQL版本:mysql-5.5.28.tar.gz
所需要的软件:
cmake-2.8.8.tar.gz
mysql-5.5.28.tar.gz
二、安装前环境准备
#yum grouplist //检查开发环境是否安装了 没有执行下面命令安装: #yum groupinstall "Development Libraries" -y #yum groupinstall "Development Tools" -y
三、安装cmake
# tar xf cmake-2.8.8.tar.gz # cd cmake-2.8.8 # ./configure # make # make install
四、为MySQL准备数据存放目录
# fdisk /dev/sdb (特意为mysql准备一块磁盘) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +20G //设置分区大小 Command (m for help): t //修改分区类型 Selected partition 1 Hex code (type L to list codes): 8e //类型为8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdb: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 2610 20964793+ 8e Linux LVM Command (m for help): w //保存 The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. #partprobe /dev/sdb1 //同步分区信息 #pvcreate /dev/sdb1 //创建PV Writing physical volume data to disk "/dev/sdb1" Physical volume "/dev/sdb1" successfully created #vgcreate myvg /dev/sdb1 //创建VG Volume group "myvg" successfully created #lvcreate -L 10G -n mydata myvg //创建LV Logical volume "mydata" created #lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert mydata myvg -wi-a- 10.00G #mke2fs -j /dev/myvg/mydata //格式化文件系统 #mkdir /mydata //创建LV的挂载目录 #vim /etc/fstab //设置开机自动挂载 /dev/myvg/mydata /mydata ext3 defaults 0 0 -->添加这行内容就可以 #mount -a //加载/etc/fstab文件 #mkdir /mydata/data //创建MySQL数据文件存放的目录
五、创建用户和组
#groupadd -r mysql #useradd -r -g mysql -s /sbin/nologin mysql #chown -R mysql.mysql /mydata/data
六、安装mysql
1、解压安装MySQL
#tar xf mysql-5.5.28.tar.gz #cd mysql-5.5.28 #cmake . -LH #cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/mydata/data \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DWITH_LIBWRAP=0 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci #make #make install
2、初始化mysql
# cd /usr/local/mysql/ # chown -R :mysql . //修改属组为mysql # scripts/mysql_install_db --user=mysql --datadir=/mydata/data
3、修改配置文件
# cd /usr/local/mysql/ # cp support-files/my-large.cnf /etc/my.cnf # cp support-files/mysql.server /etc/init.d/mysqld # chkconfig --add mysqld # chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
4、启动MySQL服务
# service mysqld start
5、配置mysql登录密码
# /usr/local/mysql/bin/mysqladmin -u root password '123456' # /usr/local/mysql/bin/mysql -uroot -p
6、添加Mysql环境变量
# cd /etc/profile.d/ # vim mysql.sh //添加如下一行内容: export PATH=$PATH:/usr/local/mysql/bin # chmod +x mysql.sh # . /etc/profile.d/mysql.sh
以上完成编译安装MySQL!!!