mysql基础-新版5.7.10源码安装-记录(一)

0x01

  MySQL 从 5.5 版本开始,通过 ./configure 进行编译配置方式已经被取消,取而代之的是 cmake 工具

  引用一句话

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

  所以首先要安装cmake 可以源码安装也可以 使用已经编译好的rpm包进行安装

  yum安装  yum install cmake -y

  源码安装  下载源码 wget --no-check-certificate https://www.cmake.org/files/v3.4/cmake-3.4.1.tar.gz

  解压 cmake     tar -zxvf cmake-3.4.1.tar.gz

  编译安装 ./configure --prefix=/usr/local/cmake  make && make install

  做个软链接 ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake

  执行 cmake --help  成功!

0x02

  开始安装源码mysql

  在搜狐的镜像下载源码

  wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.10.tar.gz

  解压源码包

  tar -zxvf mysql-5.7.10.tar.gz

  根据自己的要求选择需要编译的模块

  建立mysql安装目录及数据存放的目录

  mkdir /usr/local/mysql   ----安装文件的目录

  mkdir /mydata/mysql/log   ----二进制日志目录,做主从同步使用

  mkdir /mydata/mysql/data  ----数据库数据目录  PS:数据目录一定不要和mysql程序安装目录放在一起

  创建mysql 用户和组

  groupadd -r -g 306 mysql    ---创建一个mysql组指定gid 为306 -r是创建为一个系统用户

  useradd -g mysql -u 306 -r -s /sbin/nologin mysql    ---创建用户mysql 指定uid 为306 shell为非登录shell的系统用户 归属mysql组

  开始编译安装 ,但是报错 如下

进行下载对应包即可

wget -c http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

解压到指定文件并改名

tar -zxvf boost_1_59_0.tar.gz -C /tmp

mv /tmp/boost_1_59 /usr/local/boost

再编译安装

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=/usr/local/boost

上面编译完成 make 过程曲折,一直过不去,后来根据大神经验 

http://www.lengdo.com/blog/view/id/52.html 

http://blog.csdn.net/mchdba/article/details/50354213

发现非常好用内存,故 更改测试环境虚拟机内存至 4 G 才解决

后面make install 很顺利,完成mysql源码安装

下面开始初始化准备工作:如下

  更改安装好的mysql路径下的文件拥有组

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

  更改mysql的数据目录和日志目录拥有人和拥有组

  创建目录 mkdir /var/run/mysql

  复制默认配置文件到对应目录  

  cp support-files/my-default.cnf /etc/my.cnf

my.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.

# The following options will be passed to all MySQL clients
[client]
port     = 3306
socket   = /tmp/mysql.sock


# The MySQL server
[mysqld]
table_open_cache        = 64
max_allowed_packet      = 16M
myisam_repair_threads   = 1
myisam_sort_buffer_size = 8M

# File Path
pid-file  = /var/run/mysql/mysql.pid
#log-error = /var/log/mysql/error.log
log-error = /mydata/mysql/log/error.log

# 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
log-bin = /mydata/mysql/log/mysql-bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
datadir = /mydata/mysql/data
# port = .....
# server_id = .....
# socket = .....

# binary logging format - mixed recommended
binlog_format = mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1

# 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
key_buffer_size      = 16M
read_buffer_size     = 2M
sort_buffer_size     = 2M
join_buffer_size     = 16M
read_rnd_buffer_size = 2M

# Other Switch Settings
performance_schema   = OFF

# Recommended in standard MySQL setup
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqldump]
quick
max_allowed_packet = 16M


[myisamchk]
read_buffer      = 2M
write_buffer     = 2M
key_buffer_size  = 20M
sort_buffer_size = 20M                 

  开始初始化

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

初始化密码是 g2gd_/0y0,+I

  复制mysql的自动启停脚本

  cp support-files/mysql.server /etc/init.d/mysql

将mysql服务添加到管理服务中,让其开机启动

  chkconfig --add mysqld

  chkconfig --list | grep mysqld

启动mysql

使用刚才上面生成密码 进入mysql

登录成功,迅速修改root密码

alter user 'root'@'localhost' identified by 'your password';

flush privileges;

将mysql客户端设置环境变量,让其正常使用

通过 如下添加mysql.sh

vim /etc/profile.d/mysql.sh   ---- 添加 ----> export PATH=/usr/local/mysql/bin:$PATH

让其生效

source /etc/profile.d/mysql.sh

原文地址:https://www.cnblogs.com/autopwn/p/5074634.html