一:编译mysql

    useradd -M -s /sbin/nologin mysql                #创建mysql用户

    yum -y install cmake                            #安装cmake

    tar zxvf mysql-5.5.22.tar.gz                    #解压mysql源码包

    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -            DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETS=all            #配置mysql编译参数

    make                                 #编译 

    make install                         #安装mysql



二:初始化mysql

    chown  -R  mysql:mysql  /usr/local/mysql            #修改mysql目录属主

    ln -s /usr/local/mysql/bin/* /usr/local/bin            #创建命令链接

    cp  /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf    #复制配置文件

    cp  /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld        #复制启动脚本

    chmod +x /etc/init.d/mysqld            #赋予执行权限

    /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data                #初始化

        初始化参数说明:

            --user:指定mysql的程序用户

            --basedi:指定mysql的主目录

            --datadir:指定mysql的数据库目录

    service mysqld start        #启动mysql



三:常用编译参数

    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql        #指定安装目录 

    -DMYSQL_DATADIR=/usr/local/mysql/data      #指定数据库存放目录

    -DSYSCONFDIR=/etc         #指定mysql配置文件

    -DDEFAULT_CHARSET=utf8   #使用utf8字符 

    -DDEFAULT_COLLATION=utf8_general_ci #校验字符 

    -DEXTRA_CHARSETS=all   #安装额外的编码集

    -DWITH_MYISAM_STORAGE_ENGINE=1 #安装 myisam 存储引擎 

    -DWITH_INNOBASE_STORAGE_ENGINE=1 #安装 innodb 存储引擎 

    -DWITH_ARCHIVE_STORAGE_ENGINE=1 #安装 archive存储引擎 

    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 #安装 blackhole存储引擎 

    -DENABLED_LOCAL_INFILE=1 #允许从本地导入数据 

     -DMYSQL_TCP_PORT=3306 #MySQL 监听端口 

    -DMYSQL_USER=mysql #MySQL 用户名  

    -DWITH_SSL=yes #SSL 

    -DWITH_MEMORY_STORAGE_ENGINE=1 #安装 memory 存储引擎 

    -DWITH_FEDERATED_STORAGE_ENGINE=1 #安装 frderated 存储引擎 

    -DINSTALL_PLUGINDIR=/usr/local/mysql/plugin #插件文件及配置路径