#源码包安装MySQL数据库
[root@domain ]# yum -y install gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake bison perl curl-devel
#安装MySQL
[root@domain cmake-3.0.2]# groupadd -r mysql
[root@domain cmake-3.0.2]# useradd -r -g mysql -s /sbin/nologin mysql
[root@domain cmake-3.0.2]# mkdir -p /data/mysql#创建数据库目录
[root@domain cmake-3.0.2]# chown -R mysql:mysql /data/mysql
[root@domain cmake-3.0.2]# mkdir -p /usr/local/mysql#创建安装目录
[root@domain cmake-3.0.2]# cd /usr/local/src
[root@domain src]# tar zxvf mysql-5.6.21.tar.gz
[root@domain src]# cd mysql-5.6.21
[root@domain mysql-5.6.21]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
[root@domain mysql-5.6.21]# make
[root@domain mysql-5.6.21]# make install
[root@domain mysql-5.6.21]# rm -rf /etc/my.cnf
[root@domain mysql-5.6.21]# cd /usr/local/mysql
[root@domain mysql-5.6.21]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
[root@domain mysql-5.6.21]# ln -s /usr/local/mysql/my.cnf /etc/my.cnf
[root@domain mysql-5.6.21]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@domain mysql-5.6.21]# chmod 755 /etc/init.d/mysqld
[root@domain mysql-5.6.21]# chkconfig mysqld on
[root@domain mysql-5.6.21]# vim /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql #MySQL程序安装路径
datadir=/data/mysql #MySQl数据库存放目录
[root@domain mysql-5.6.21]# service mysqld start
[root@domain mysql-5.6.21]# vim /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
[root@domain mysql-5.6.21]# source /etc/profile
[root@domain mysql-5.6.21]# mysqladmin -u root password #设置Mysql密码