作为博主这样的Linux菜鸟,CentOS下最喜欢的就是yum安装。但有时候因为特殊情况(例如被墙等),某些软件可能没办法直接通过yum来安装,这时候我们可以使用编译安装或者直接二进制文件安装。
本博文用于记录编译安装MySQL的过程:
1.首先下载相关资源:
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.gzmv /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 mysqlchown -R mysql.mysql /usr/local/mysql /binlog/mysqlog /data/mysql
6.编译安装
cd mysql-5.7.19cmake \-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=3306server-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=0log-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-filescp 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');
打完收工。