作为博主这样的Linux菜鸟,CentOS下最喜欢的就是yum安装。但有时候因为特殊情况(例如被墙等),某些软件可能没办法直接通过yum来安装,这时候我们可以使用编译安装或者直接二进制文件安装。
本博文用于记录编译安装MySQL的过程:
1.首先下载相关资源:
组件 | 官方网站 | 下载地址 | 备注 |
mysql | http://dev.mysql.com/ | https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz | mysql源码 |
Boost | http://www.boost.org/ | http://120.52.73.44/nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz | 编译时使用,必须是Boost 1.59.0 |
2.安装依赖包:
yum install -y gcc gcc-c++ autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake libaio libaio-devel autoconf bzr bison libtool
3.解压并安装Boost(拷贝至/usr/local/boost目录)
tar -zxf boost_1_59_0.tar.gz
mv /tmp/boost_1_59_0 /usr/local/boost
4.解压MySQL源玛
tar -zxf mysql-5.7.19.tar.gz
5.准备MySQL数据,日志等路径,并创建mysql用户,赋予mysql用户相关文件夹权限
mkdir -p /usr/local/mysql /binlog/mysqlog /data/mysql
groupadd -r mysql
useradd -g mysql -r -d /data/mysql mysql
chown -R mysql.mysql /usr/local/mysql /binlog/mysqlog /data/mysql
6.编译安装
cd mysql-5.7.19
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DSYSCONFDIR=/etc/my.cnf \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_BOOST=/usr/local/boost \
make && make install
7.编辑my.cnf文件
vi /etc/my.cnf
几个路径的地方记得修改:
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
basedir = /usr/local/mysql
# basic setting
user=mysql
port=3306
server-id=11
#log
slow_query_log_file = /binlog/mysqlog/slow.log
slow_query_log = 1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/binlog/mysqlog/err.log
8.初始化MySQL
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql --socket=/tmp/mysql.sock --log-error=/binlog/mysqlog/err.log --log-bin=/binlog/mysqlog/mysql-bin
9.添加MySQL服务
cd /tmp/mysql-5.7.19/support-files
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
10.启动MySQL
/etc/init.d/mysql start
11.查看mysql进程
ps -ef | grep mysql
12.建立Mysql映射
ln -s /usr/local/mysql/bin/mysql /usr/bin
13.查找mysql初始密码
sudo grep 'temporary password' /binlog/mysqlog/err.log
14.初次登录,修改密码
mysql -uroot -p
set password=password('newpassword');
打完收工。