二进制包安装MySQL5.7.29

还是5.7.29,还是CentOS 7

二进制包安装MySQL

一、下载

  1. 安装依赖包

    yum install ncurses-devel.x86_64 libaio.x86_64 -y
    
  2. 下载MySQL二进制包

    方法一:使用wget命令直接下载

    wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.29-el7-x86_64.tar.gz
    

    方法二:到官网下载,然后上传到Linux

    https://downloads.mysql.com/archives/community/

    选择对应的版本

  3. 解压缩

    # 解压缩
    tar xf mysql-5.7.29-el7-x86_64.tar
    tar -zxf mysql-5.7.29-el7-x86_64.tar.gz
    
    # 移动到/usr/local下
    mv mysql-5.7.29-el7-x86_64 /usr/local/mysql
    

二、修改配置文件并初始化

  1. 前提工作

    # 创建mysql用户
    useradd -r -s /sbin/nologin mysql
    
    # 建立工作目录
    mkdir -p /data/mysql/{data,log}
    
    # 授权目录
    chown -R mysql.mysql /data/mysql
    chown -R mysql.mysql /usr/local/mysql
    
  2. 编辑配置文件

    cat > /etc/my.cnf << EOF
    [client]
    default-character-set = utf8mb4
    port = 3306
    socket = /data/mysql/mysql.sock
    
    [mysqld]
    server_id = 1
    character-set-server = utf8
    user = mysql
    port = 3306
    socket = /data/mysql/mysql.sock
    basedir = /usr/local/mysql
    datadir = /data/mysql/data
    log-error = /data/mysql/log/mysql_error.log
    log-bin = /data/mysql/log/mysql-bin
    binlog_format = ROW
    pid-file = /data/mysql/mysql.pid
    open_files_limit = 8192
    innodb_buffer_pool_size = 512M
    
    [mysql]
    auto-rehash
    prompt = '\u@\h [\d]> '
    EOF
    
  3. 初始化

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

三、启动MySQL

  1. 添加环境变量

    echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
    source /etc/profile
    
  2. 启动

    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
    /etc/init.d/mysql start
    chkconfig --add mysql
    
  3. 获取默认密码登录

    # 获取默认密码
    temp_passwd=`cat /data/mysql/log/mysql_error.log | grep "temporary password" | awk '{print $NF}'`
    
    # 使用默认密码登录
    mysql -uroot -p$temp_passwd
    
    # 修改密码
    root@localhost [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword2233$';
    

二进制包安装mysql完成!

posted @ 2021-05-27 11:23  Charramma  阅读(102)  评论(0编辑  收藏  举报