linux编译安装mysql5.7

听说编译mysql5.7编译很消耗内存,今天就在1g内存的树莓派下尝试一下

下载

wget mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.17.tar.gz
因为官方下载地址速度太慢了,所以我直接去搜狐镜像站下载了
tar -zxvf mysql-boost-5.7.17.tar.gz

编译安装

  • 首先安装cmake
    1.下载
    wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz
    tar -zxvf cmake-3.7.2.tar.gz
    2.编译安装
    安装方法在readme里有
    ./bootstrap --prefix=/usr/local/cmake
    make
    这里可能有人会问为什么不加上-j参数,因为我加上后我的树莓派总是编译失败,所以不加了
    make install

之后执行
/usr/local/cmake/bin/cmake . -DWITH_BOOST=/data/mysql/mysql-5.7.17/boost/boost_1_59_0
后面with——boost的意思是加上boos库,因为我们下载的mysql是带boost的所以在mysql解压出来的源码文件里就有,而前面就是cmake的路径,因为我没有把cmake设置到系统的环境变量里,所以就只能用绝对路径了

  • 然后报错
CMake Error at cmake/readline.cmake:64 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:107 (FIND_CURSES)
  cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:483 (MYSQL_CHECK_EDITLINE)


-- Configuring incomplete, errors occurred!
See also "/data/mysql/mysql-5.7.17/CMakeFiles/CMakeOutput.log".
See also "/data/mysql/mysql-5.7.17/CMakeFiles/CMakeError.log".

提示要安装libncurses5-dev
那就执行
sudo apt-get install libncurses5-dev

然后再次执行
/usr/local/cmake/bin/cmake . -DWITH_BOOST=/data/mysql/mysql-5.7.17/boost/boost_1_59_0
make
果然在
[ 44%] Building CXX object sql/CMakeFiles/sql.dir/item_geofunc.cc.o
这个的时候因为内存太小所以编译失败。

  • 那么就增加swap空间了
    1.创建swap文件
    sudo dd if=/dev/zero of=/swapfile bs=64M count=16
    这里的大小随便设置,文件名字也可以随便取,不一定是swapfile
    2.格式化
    sudo mkswap /swapfile
    3.启用swap空间
    sudo swapon /swapfile

然后
你可以free -m看一下swap空间是不是真的使用了,之后
make
编译的时间很长的,我用的是树莓派,所以更长,所以就没有统计时间了,你可以重复多执行几遍make
然后
make install

简单的配置

  • 首先建立mysql用户
    先说一下为什么要建立mysql用户,首先当什么很牛逼的黑客通过mysql拿到了数据库的权限后,它是不能拿到root权限的,所以两个字安全
    groupadd mysql
    useradd -g mysql mysql

  • 然后修改一些文件夹和文件的权限
    /usr/local/
    chown -R mysql mysql
    chgrp -R mysql mysql

  • 初始化mysql配置表
    cd mysql
    bin/mysqld --initialize --user=mysql
    然后要注意了,注意了,看输出的最后一行

2017-02-10T07:41:54.045121Z 1 [Note] A temporary password is generated for root@localhost: 1!HD!ijywTi)

1!HD!ijywTi这是root的密码
然后
bin/mysql_ssl_rsa_setup
这个我就不知道干什么的了,知道的求评论

  • 将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data/目录下所有文件的所有者
    chown -R root .
    chown -R mysql data

  • 复制配置文件
    cp support-files/my-default.cnf /etc/my.cnf

  • 之后启动mysql
    bin/mysqld_safe --user=mysql &

  • 配置配置文件

# 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 = /usr/local/mysql
#--mysql目录
datadir = /usr/local/mysql/data
#--数据库目录
# port = 3306
#--数据库端口
# server_id = .....
socket = /tmp/mysql.sock
#--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 
  • 复制mysql启动文件
    cp

  • 最后启动测试一下
    一直显示密码错误,可能是因为密码中有!的缘故,所以直接修改密码吧
    结束mysql所有进程
    然后
    mysqld_safe --skip-grant-tables --skip-networking &
    这个命令在mysql的bin目录下
    然后
    mysql -p
    mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
    把密码改成自己的密码就好了
    然后结束mysql所有进程
    然后报错
    ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
    使用指定用户启动就好了
    ./mysqld --user=root
    然后登陆
    ./mysql -uroot -p
    再次修改密码,因为刚才这样是创建不了数据库的
    set password=password('密码');

    原文作者:bboysoul
    原文地址: https://www.jianshu.com/p/aa9dbaef9920
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞