首页 Linux正文

LAMP架构之MySQL 5.7(CMake)

王昊 Linux 2019-07-29 195 0

MySQL5.7版本更新后有很多变化,比如json等,连安装都有变化,安装必须要BOOST库,不过MySQL的官网源码有带boost库的源码和不带boost库的源码两种,因此有两种安装方式,其实都是一样的,仅仅是不带boost库源码的需要单独安装boost

下载源码包,本次用的是带boost库的源码包

cd /usr/local

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz

卸载系统自带的boots库

yum -y remove boost-*

解压

tar xf mysql-boost-5.7.25.tar.gz

cd mysql-5.7.25

下载相关依赖

yum install -y cmake ncurses-devel ncurses-devel autoconf ncurses bison gcc gcc-c++ make

添加用户和用户组

groupadd mysql

useradd -M -s /sbin/nologin -r -g mysql mysql

创建安装目录和数据存放目录

mkdir -p /usr/local/mysql

将boost移到 mysql 中

mv boost/ /usr/local/mysql

生成Makefile

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=l \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/mysql/boost

CMake选项参考:https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

编译时会占用大量的系统资源,建议使用多个核心同时进行编译,否则可能会编译失败

查看服务器cpu数

grep processor /proc/cpuinfo | wc -l

2

编译安装

make -j 2 && make install

修改目录权限

chown -R mysql:mysql /usr/local/mysql

将原服务器配置文件移动备份或删除

mv /etc/my.cnf{,.bak}

因5.7版本无此配置模板文件/server/mysql/support-files/my-default.cnf

vim /etc/my.cnf

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#default

user = mysql

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

pid-file = /usr/local/mysql/data/mysql.pid

socket = /usr/local/mysql/mysql.sock

character-set-server=utf8

[client]

socket = /usr/local/mysql/mysql.sock

生成服务启动脚本

grep chkconfig ./* -R -color

复制配置文件

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

更改权限

chmod +x /etc/init.d/mysqld

加入系统服务

chkconfig –add mysqld

设置开机自启项

chkconfig mysqld on

chkconfig –list mysqld

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

初始化数据库

/usr/local/mysql/bin/mysqld –initialize-insecure –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data

启动服务

service mysqld restart

 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
 SUCCESS! 

service mysqld restart

Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!

优化调用命令路径

方法一:

添加path路径:

vim /etc/profile //添加下面2行 在文件的结尾

export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

使修改生效

source /etc/profile

方法二:

ln -s /usr/local/mysql/bin/* /usr/local/bin/

登录数据库

方法一:无密码,直接回车即可登录

mysql -u root -p

方法二:设置密码再登录

mysqladmin -u root password “123456”

mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

mysql -u root -p

输入刚刚设置的密码,即可登录

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论