• 二进制安装MySQL



    • 环境说明
      CentOS Linux release 7.9.2009 (Core) 最小化安装
      阿里centos7源

    1 下载源码包

    https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.6/
    https://mirrors.aliyun.com/mysql/MySQL-5.7/

    2 安装

    2.1 for mysql 5.6

    #!/bin/bash
    PKG_NAME=mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz && echo ${PKG_NAME}
    dnf -y install libaio autoconf &> /dev/null && echo '--> install depends success'
    
    useradd -r -s /bin/false mysql
    # wget https://mirrors.aliyun.com/mysql/MySQL-5.6/${PKG_NAME} -P /opt
    tar zxf /opt/${PKG_NAME} -C /usr/local/src
    ln -s /usr/local/src/mysql-5.6.51-linux-glibc2.12-x86_64 /usr/local/mysql
    export PATH=$PATH:/usr/local/mysql/bin
    echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
    
    mkdir -p /data/mysql
    chown -R mysql.mysql /data/ /usr/local/mysql/
    # cd /usr/local/mysql  && scripts/mysql_install_db --basedir=/usr/local/mysql/ --user=mysql --datadir=/data/mysql
    /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
    
    cat > /etc/my.cnf << eof
    [mysqld]
    socket=/data/mysql.sock
    user=mysql
    symbolic-links=0
    datadir=/data/mysql
    innodb_file_per_table=1
    
    [client]
    port=3306
    socket=/data/mysql.sock
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/tmp/mysql.sock
    eof
    
    /etc/init.d/mysql.server start
    chkconfig --add mysql.server
    

    image

    2.2 for mysql 5.7

    # env
    PKG_NAME=mysql-5.7.34-el7-x86_64.tar.gz && echo ${PKG_NAME}
    dnf -y install libaio &> /dev/null && echo '  --> install libaios success'
    # dnf -y install libaio numactl-libs
    # wget https://mirrors.aliyun.com/mysql/MySQL-5.7/mysql-5.7.34-el7-x86_64.tar.gz -P /tmp
    
    useradd -r -s /bin/false mysql
    mkdir -p /data/mysql
    chown -R mysql:mysql /data/
    echo '  --> 1- set env successful'
    
    # prepare
    tar zxf ${PKG_NAME} -C /usr/local/src
    ln -s /usr/local/src/mysql-5.7.34-el7-x86_64 /usr/local/mysql
    export PATH=$PATH:/usr/local/mysql/bin
    echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
    echo '  --> 2- pkg prepare successful'
    
    # config
    cat > /etc/my.cnf << eof
    [mysqld]
    datadir=/data/mysql
    skip_name_resolve=1
    socket=/data/mysql/mysql.sock    
    log-error=/data/mysql/mysql.log
    pid-file=/data/mysql/mysql.pid
    
    [client]
    socket=/data/mysql/mysql.sock
    eof
    echo '  --> 3- add config successful'
    
    # initialize
    # 生成数据库文件,并提取root密码
    mysqld --initialize --user=mysql --datadir=/data/mysql
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    grep password /data/mysql/mysql.log
    chkconfig --add mysqld
    service mysqld start
    echo '  --> 4- initialize successful'
    echo '  --> 5- use `mysqladmin -uroot -p'xxxxxx' password new_password` to set new password'
    

    image

    3 初始化

    mysqladmin -u root -h localhost password '123456'  # 初始化设置root密码即可使用
    mysql_secure_installation      #ver5.7必须通过此方式初始化
    # 设置数据库管理员root口令
    # 禁止root远程登录
    # 删除anonymous用户帐号
    # 删除test数据库
    

    PS

    # sed -n 147,158p /usr/local/mysql/bin/mysql_secure_installation
    sub make_config {
      my $password = shift;
    
      my $esc_pass = basic_single_escape($rootpass);
      write_file($config,
                 "# mysql_secure_installation config file",
                 "[mysql]",
                 "user=root",
                 "socket=/data/mysql.sock",
                 "password='$esc_pass'",
                 "connect-expired-password");
    }
    
  • 相关阅读:
    mysql_数据查询_嵌套查询
    mysql_数据查询_连接查询
    大白_uva10795_新汉诺塔
    codeforces_731C_[dfs][并查集]
    Ajax+asp.net实现用户登陆 转自http://www.shangxueba.com/jingyan/2933319.html
    entity framework 中一些常用的函数 转自http://www.cnblogs.com/williamzhu/
    转自新浪博客的网页运作原理
    一些ASP.NET的小知识点
    。。
    .NET
  • 原文地址:https://www.cnblogs.com/firewalld/p/14816429.html
Copyright © 2020-2023  润新知