有时候需要更灵活的配置,就需要对软件进行编译安装。下面我们来编译安装Mysql5.7.21,源码程序可以到链接: https://pan.baidu.com/s/1niuiZN1aNLmCOSYNq52msg 提取码: gr9q 这里去获得
先解压源码包
tar -xzvf mysql-5.7.21.tar.gz
tar -xzvf boost_1_59_0.tar.gz
安装软件之间,先安装gcc,以及一些必要库
yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake
创建Mysql用户
groupadd mysql
useradd -r -g mysql -s /bin/false -M mysql
mkdir -p /home/mysql/{data,log,tmp}
chown -R mysql:mysql /home/mysql/
boots库移动到/usr/local目录
mv boost_1_59_0 /usr/local
开始编译安装mysql5.7,这个消耗时间根据你机器的性能来决定
cd mysql-5.7.21
cmake . -DCMAKE_INSTALL_PREFIX=/app/soft/mysql57 -DMYSQL_DATADIR=/app/soft/mysql57/data -DSYSCONFDIR=/app/soft/mysql57/my.cnf -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3307 -DMYSQL_USER=mysql -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 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DWITH_BOOST=/usr/local/boost_1_59_0
make
make install
数据库初始化
mkdir /app/soft/mysql57/data #确认数据保存目录
mkdir -p /app/soft/mysql57/logs/ #确认日志保存目录
cd /app/soft/mysql57/
bin/mysqld --initialize-insecure --user=mysql --basedir=/app/soft/mysql57 --datadir=/app/soft/mysql57/data #初始化
cp /app/soft/mysql57/support-files/mysql.server /etc/init.d/mysql #mysql启动脚本
touch /app/soft/mysql57/logs/mariadb.log
chown mysql:mysql /app/soft/mysql57 -R
把mysql加入系统自启动
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list
chkconfig --level 2345 mysql on
修改mysql配置文件vi /etc/my.cnf
[mysqld]
datadir=/app/soft/mysql57/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/app/soft/mysql57/logs/mariadb.log
pid-file=/tmp/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
至此安装完毕
启动mysql
/etc/init.d/mysql start
默认访问数据库,root密码为空
/app/soft/mysql57/bin/mysql -uroot