编译安装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/
# 下载cmakewget https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz# 解压tar zxvf cmake-3.9.0.tar.gzcd 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/boostwget http://download.0-n-0.com/mysql/boost_1_59_0.tar.gztar zxvf boost_1_59_0.tar.gz mv boost_1_59_0 /usr/local/boost# 下载MySQLwget http://download.0-n-0.com/mysql/mysql-5.7.22.tar.gz# 解压tar zxvf mysql-5.7.22.tar.gzcd 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目录下,并更名为mysqldcp ./support-files/mysql.server /etc/init.d/mysqld# 为mysqld增加执行权限chmod +x /etc/init.d/mysqld# 配置mysql开机启动chkconfig --add mysqldchkconfig mysqld onchkconfig | grep mysqlmysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off# 进入mysql的程序目录cd /usr/local/mysql# 创建mysql-files目录,修改权限mkdir mysql-fileschmod 750 mysql-fileschown -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 -pEnter password:YwSv2mg(tryrmysql>set password for 'root'@'localhost'=password('root');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql># 修改密码后,重新登陆即可[root@localhost mysql]# mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.7.13 Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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 int866 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;874875 (void) sigemptyset(&nset);876 (void) sigaddset(&nset, SIGWINCH);877 (void) sigprocmask(SIG_BLOCK, &nset, &oset);878879 area = NULL;# 然后重新编译安装,会很快make && make install
3.提示找不到/tmp/mysql.sock
# 修改my.cnfvim /etc/my.cnf# 加入以下内容[client]default-character-set=utf8port =3306socket =/var/lib/mysql/mysql.sock
本文题目:编译安装MySQL-5.7.22
文章转载:http://scjbc.cn/article/cpdjh.html