CentOS6.8使用cmake安装MySQL5.7.18

安装MySQL相关依赖:

yum -y install gcc gcc-c++ gcc-g77 make cmake bison ncurses-devel autoconf automake zlib* fiex* libxml*  libmcrypt* libtool-ltdl-devel* libaio libaio-devel bzr libtool ncurses5-devel imake libxml2-devel expat-devel

安装boost_1_59_0(必须是该版本):

1、获取源码:假如下载到/usr/local/src目录下,则进入目录cd /usr/local/src,然后获取源码软件包

wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download

2、解压:

tar -xzvf boost_1_59_0.tar.gz

3、进入boost目录:

cd boost_1_59_0

4、进行配置:

./bootstrap.sh

5、编译:

./b2

6、安装:

./b2 install

编译安装完成后,会把boost头文件拷贝到/usr/local/include/目录下,库文件在/usr/local/lib/下。

安装cmake(最新版本):

1、获取源码:依然下载到/usr/local/src目录下,cd /usr/local/src,获取软件包

wget https://cmake.org/files/v3.8/cmake-3.8.0.tar.gz

2、解压:

tar -xzvf cmake-3.8.0.tar.gz

3、进入cmake目录:

cd cmake-3.8.0

4、执行bootstrap:

./bootstrap

5、编译

gmake

6、安装

gmake install 

安装mysql5.7.18:

1、添加mysql用户和所属组:

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql

2、创建mysql安装目录和数据目录

mkdir /usr/local/mysql
mkdir /usr/local/mysql/data

3、修改mysql目录所有者

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

4、获取mysql源码包:还在/usr/local/src目录下

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

5、解压:

tar -xzvf mysql-5.7.18.tar.gz

6、进入mysql目录:

cd mysql-5.7.18

7、cmake编译配置:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_DATADIR=/usr/local/mysql/mydata \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_SSL=yes \
-DWITH_BOOST=/usr/local/src/boost_1_59_0 \
-DMYSQL_USER=mysql

8、编译安装:

make && make install

9、创建、修改配置文件

    mysql服务启动时,默认读取/etc/my.cnf配置文件。但由于在 5.7.18 开始,二进制包不再包含示例文件 my-default.cnf,所以我从 5.7.17 版本中提取了样例,但是发现里面也没有太多项配置,my-default.cnf 内容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
 
[mysqld]
 
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
 
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
 
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
 
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 
 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

    其实,这些项都是命令行的参数,在官网上,找到需要配置的项按需要进行配置,例如:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]
datadir=/usr/local/mysql/data/
socket=/usr/local/mysql/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

# include all files from the config directory
!includedir /etc/my.cnf.d

    将以上内容保存至/etc/my.cnf文件中(若my.cnf已存在,请根据实际情况判断是否可以更改此文件)。

10、到mysql的安装目录bin下,初始化数据库

cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql --socket=/usr/local/mysql/mysql.sock

运行后最后一句[note] 生成了一个mysql默认密码,复制到一个地方,保存下来。 

11、添加mysql服务,回到mysql安装目录,进入support-files目录:

cd ../support-files

复制启动文件:

 cp -a mysql.server /etc/init.d/mysql  //-a 可以把原来的属性一起复制过来

12、启动mysql

service mysql start

(1)若出现:【log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.】错误,请先确认/var/log/mariadb/mariadb.log文件是否存在,若不存在,则创建,并给mysql用户授权即可。

# mkdir /var/log/mariadb
# touch /var/log/mariadb/mariadb.log
# chown -R mysql:mysql  /var/log/mariadb/

(2)若出现:【Starting MySQL...The server quit without updating PID file [FAILED]cal/mysql/data/***.pid).】错误,可能进程里已经存在mysql进程,用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9  进程号”或直接killall mysqld强制关闭mysql进程,然后重新启动mysqld!

13、设置开机自启

chkconfig mysql on

或vim /etc/rc.local在最后再加一行:service mysql start 

14、登录mysql

到mysql安装目录的bin下:

cd bin
./mysql -uroot -p
Enter password:   //输入之前保存的默认密码

15、修改root密码

SET PASSWORD = PASSWORD('mysql123');

16、刷新mysql的系统权限相关表

flush privileges;

17、退出mysql:

quit;

18、最后做一个软链接方便使用mysql

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

至此,编译安装结束。

以上就是本文的全部内容,希望对大家的学习有所帮助。

 

文章来源:卿柠 MySQL的my.cnf文件(解决5.7.18下没有my-default.cnf)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值