1、mysql5.5源码安装
yum install -y cmake ncurses-devel ncurses cd /usr/src wget -c https://cdn.mysql.com/archives/mysql-5.5/mysql-5.5.20.tar.gz tar -xzf mysql-5.5.20.tar.gz cd mysql-5.5.20 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55/ \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306 \ -DWITH_XTRADB_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ -DWITH_BIG_TABLES=1 \ -DWITH_DEBUG=0 make make install 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 --level 35 mysqld on mkdir -p /data/mysql useradd mysql /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql/ ln -s /usr/local/mysql55/bin/* /usr/bin/ /etc/init.d/mysql restart
2、mysql5.7源码安装(需要先安装boost)
cd /usr/src
wget -c http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz tar -zxf boost_1_59_0.tar.gz mv boost_1_59_0 /usr/local/boost yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison wget -c https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21.tar.gz tar -xzf mysql-5.7.21.tar.gz cd mysql-5.7.21 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \ -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ -DMYSQL_DATADIR=/data/mysql/ \ -DSYSCONFDIR=/etc \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306 \ -DWITH_XTRADB_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ -DWITH_BIG_TABLES=1 \ -DWITH_DEBUG=0 \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/usr/local/boost make make install
将/etc/my.cnf修改为如下代码:
[mysqld] datadir=/data/mysql basedir=/usr/local/mysql socket=/tmp/mysql.sock pid-file=/data/mysql/mysql.pid character-set-server =utf8 skip-grant-tables symbolic-links=0 [mysqld_safe] log-error=/data/mysql/mariadb.log pid-file=/data/mysql/mariadb.pid
初始化数据库:
mkdir -p /data/mysql useradd mysql /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql cd /usr/local/mysql/ \cp support-files/mysql.server /etc/init.d/mysqld ln -s /usr/local/mysql/bin/* /usr/bin/ chkconfig --add mysqld chkconfig --level 35 mysqld on /etc/init.d/mysqld restart