坚持以客户需求至上原则
中国老牌优质服务商

编译安装MySQL-5.7.22

cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译。

服务器系统版本

++++++++++++++++++++++++++++
OS: Centos 7.4.1708 (Core)
kernel: 3.10.0-693.5.2.el7.x86_64
MySQL: mysql-5.7.22.tar.gz
++++++++++++++++++++++++++++

一、安装cmake

跨平台编译器 https://cmake.org/download/

# 下载cmake
wget https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz
# 解压
tar zxvf cmake-3.9.0.tar.gz
cd cmake-3.9.0
# 加载配置文件
./bootstrap
# 编译/安装
gmake 
gmake install

二、编译安装mysql

# 更新必要组件
yum install -y make gcc gcc-c++ ncurses-devel

# 新建mysql安装目录以及数据库存放目录
mkdir -p /usr/local/mysql /usr/local/mysql/data

# 新建boost目录,cmake编译时需要用到的组件
mkdir -p /usr/local/boost
wget http://download.0-n-0.com/mysql/boost_1_59_0.tar.gz
tar zxvf boost_1_59_0.tar.gz 
mv boost_1_59_0 /usr/local/boost

# 下载MySQL
wget http://download.0-n-0.com/mysql/mysql-5.7.22.tar.gz

# 解压
tar zxvf mysql-5.7.22.tar.gz
cd mysql-5.7.22

# 新建mysql用户,
useradd -s /sbin/nologin -M mysql
# 赋予程序目录mysql用户权限
chown -R mysql.mysql /usr/local/mysql /usr/local/mysql/data

# 加载配置
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_BOOST=/usr/local/boost/boost_1_59_0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
# 编译/安装
make 
make install

三.修改运行设置

# 复制启动程序到/etc/init.d目录下,并更名为mysqld
cp ./support-files/mysql.server /etc/init.d/mysqld
# 为mysqld增加执行权限
chmod +x /etc/init.d/mysqld
# 配置mysql开机启动
chkconfig --add mysqld
chkconfig mysqld on
chkconfig | grep mysql
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

# 进入mysql的程序目录
cd /usr/local/mysql
# 创建mysql-files目录,修改权限
mkdir mysql-files
chmod 750 mysql-files
chown -R mysql.mysql ../mysql/

# 初始化mysql
./bin/mysqld --initialize --user=mysql
# 省略6行
2016-07-04T12:45:21.242525Z 1 [Note] A temporary password is generated for root@localhost: YwSv2mg(tryr # 最后这里是密码

# ssl 环境
./bin/mysql_ssl_rsa_setup

# 重新配置权限
chown mysql.mysql ./mysql-files/

# 配置环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile

# 第一次登陆,需要修改mysql密码,否侧无法正常使用
mysql -u root -p
Enter password:YwSv2mg(tryr
mysql> set password for 'root'@'localhost'=password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>

# 修改密码后,重新登陆即可
[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.13 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql>

四.扩展延伸

1.提示中带有/var/log/mariadb/mariadb.log

# 创建mariadb文件夹
mkdir -p /var/log/mariadb
# 创建文件
touch /var/log/mariadb/mariadb.log
# 赋予mysql权限
chown mysql:mysql /var/log/mariadb/mariadb.log

2.第一次登陆出现Segmentation fault

# 回到源码目录
cd ~/mysql-5.7.20/
# 修改cmd-line-utils/libedit/terminal.c文件中的字段 area=NULL;
vim cmd-line-utils/libedit/terminal.c

# 大致如下,在最后一个
865 protected int
866 terminal_set(EditLine *el, const char *term)
867 {
868 int i;
869 /*char buf[TC_BUFSIZE];*/
870 char *area;
871 const struct termcapstr *t;
872 sigset_t oset, nset;
873 int lins, cols;
874
875 (void) sigemptyset(&nset);
876 (void) sigaddset(&nset, SIGWINCH);
877 (void) sigprocmask(SIG_BLOCK, &nset, &oset);
878
879 area = NULL;

# 然后重新编译安装,会很快
make && make install

3.提示找不到/tmp/mysql.sock

# 修改my.cnf
vim /etc/my.cnf
# 加入以下内容
[client]
default-character-set=utf8
port    =3306
socket  =/var/lib/mysql/mysql.sock
赞(11)

更专业 更快速 更方便

华夏名网VIP服务