MySQL源码安装5.7-CentOS7

时间:2021-07-20 16:25:40   收藏:0   阅读:0
  1. 如果有卸载官方自带的安装包
    rpm -qa | grep -i mysql
    rpm -qa | grep -i mariadb

    rpm -e xxxx
    #注:如上命令删除不成功,有别的软件依赖无法删除时,如下操作:
    yum remove xxxx
    或
    rpm -e --nodeps xxxx
    ```
    2. 关闭seLinux

   一、查看SELinux状态命令:
  1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态
  SELinux status: enabled
  2、getenforce ##也可以用这个命令检查
  二、关闭SELinux方法:
  1、临时关闭(不用重启机器):
  代码如下:
  setenforce 0 #设置SELinux 成为  permissive 模式 放任的 关闭
  #setenforce 1 设置SELinux 成为  enforcing  模式 强制执行 打开
  2、修改配置文件需要重启机器:
  修改/etc/selinux/config 文件
  将SELINUX=enforcing改为SELINUX=disabled
  重启机器即可

3.下载源码包安装依赖

    // 初始化目录
    mkdir -p /data/mysql/data
    mkdir -p /data/mysql/tmp
    mkdir -p /data/mysql/binlog
    mkdir -p /data/mysql/logs
    mkdir -p /data/boost
    groupadd mysql
    useradd mysql -s /sbin/nologin -M -g mysql

    -s /sbin/nologin 用户不能登录系统
    -M 不创建用户的home家目录
    -g 指定用户登录组的gid或组名
    id mysql
    // 下载源码包 并且解压 
    cd /data
    wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30.tar.gz
    yum -y install gcc gcc-c++ glibc automake autoconf libtool make openssl openssl-devel ncurses ncurses-devel cmake

    // 下载boost到/data/boost 后面的编译参数会用到
    cd /data/boost
    wget  http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

    cd /data/mysql-5.7.30
    cmake     -DCMAKE_INSTALL_PREFIX=/data/mysql     -DMYSQL_DATADIR=/data/mysql/data     -DMYSQL_UNIX_ADDR=/data/mysql/tmp/mysql.sock     -DDEFAULT_CHARSET=utf8     -DDEFAULT_COLLATION=utf8_general_ci     -DEXTRA_CHARSETS=all     -DENABLED_LOCAL_INFILE=1     -DWITH_INNOBASE_STORAGE_ENGINE=1     -DWITH_FEDERATED_STORAGE_ENGINE=1     -DWITH_BLACKHOLE_STORAGE_ENGINE=1     -DWITH_EXAMPLE_STORAGE_ENGINE=1     -DWITH_PARTITION_STORAGE_ENGINE=1     -DWITH_MYISAM_STORAGE_ENGINE=1     -DWITH_ZLIB=bundled     -DWITH_EMBEDDED_SERVER=1     -DSYSCONFDIR=/etc     -DMYSQL_TCP_PORT=3306     -DWITH_SSL=yes     -DWITH_DEBUG=0     -DDOWNLOAD_BOOST=1     -DWITH_BOOST=/data/boost

    //如果编译出现错误,请先删除CMakeCache.txt后,检查环境后再重新编译:
    //rm -rf CMakeCache.txt

    make install

    // 添加环境变量
    echo ‘export PATH=/data/mysql/bin:$PATH‘ >> /etc/profile
    source /etc/profile

    chown -R mysql:mysql /data/mysql/

    vi /etc/my.cnf

    [client]
    port = 3306
    socket = /data/mysql/tmp/mysql.sock
    default-character-set = utf8
    [mysqld]
    port = 3306
    user = mysql
    basedir = /data/mysql
    datadir = /data/mysql/data
    pid-file = /data/mysql/mysqld.pid
    socket = /data/mysql/tmp/mysql.sock
    tmpdir = /data/mysql/tmp
    character_set_server = utf8
    server-id = 1
    max_connections = 100
    max_connect_errors = 10
    log-bin = /data/mysql/binlog/mysql-bin
    log-error = /data/mysql/logs/mysql_5_7_24.err

    chown mysql:mysql /etc/my.cnf
  1. 初始化数据库,进入到安装目录
    // 数据库初始化
    cd /data/mysql/
    ./bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data

    // mysql实例开启ssl连接,进入到安装目录  https://www.cnblogs.com/mysql-dba/p/7061300.html 解释 生产环境内网一半不开启
    cd /data/mysql/
    ./bin/mysql_ssl_rsa_setup --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
    cd /data/mysql/data/
    chmod +r server-key.pem

    // 设置开机自启动
    cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
    systemctl daemon-reload
    systemctl enable mysqld.service
    chkconfig mysqld on
    systemctl start mysqld
    systemctl status mysqld

    // 第一次登录不需要密码
    mysql -uroot -p
    select user,host from mysql.user;
    set password for ‘mysql.session‘@‘localhost‘ = password(‘123456‘);
    set password for ‘mysql.sys‘@‘localhost‘ = password(‘123456‘);
    set password for ‘root‘@‘localhost‘ = password(‘123456‘);
    flush privileges;
    // 授权
    grant all privileges on *.* to root@‘%‘ identified by ‘123456‘ with grant option;
    select version();
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!