美文网首页
CentOS8安装mysql-5.7.32

CentOS8安装mysql-5.7.32

作者: loserStar | 来源:发表于2021-03-17 17:48 被阅读0次

    转自:https://www.jianshu.com/p/85bc42af03e7

    • CentOS8.x已安装MySQL8.0.17
    • 系统为:CentOS8.0.1905
    • 最终安装MySQL版本:5.7.29

    一、卸载MySQL8

    1、查看版本
    mysql --version
    
    
    image
    2、查看安装的包
    rpm -qa | grep mysql
    
    
    image
    3、卸载已安装MySQL8
    rpm -qa | grep mysql | xargs rpm -e --nodeps
    
    

    删除MySQL配置文件及其目录

    rm -rf /etc/my.cnf /etc/my.cnf.d
    
    

    二、离线安装指定版本的MySQL

    1、安装必要的包
    yum install libncurses*
    
    
    2、官网下载tar包

    官网地址:https://dev.mysql.com/downloads/mysql/
    (Looking for the latest GA version?)

    Select Version: 5.7.29
    Select Operating System: Source Code
    Select OS Version: Generic Linux(Architecture Independent)

    或者使用以下命令下载

    cd /usr/local/src
    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-el7-x86_64.tar.gz
    
    

    将离线下载的tar上传至/usr/local/src目录下

    3、创建安装账户
    mkdir /usr/local/mysql
    useradd -s /bin/false -d /usr/local/mysql  mysql
    
    
    4、安装过程
    # 此过程有点长,耐心等待
    tar -xvzf mysql-5.7.21-el7-x86_64.tar.gz -C /usr/local/mysql/
    cd /usr/local/mysql/mysql-5.7.21-el7-x86_64/
    mv * ../
    cd ..
    rmdir mysql-5.7.21-el7-x86_64/
    mkdir data
    chown -R mysql.mysql ../mysql
    cd bin
    ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
    
    

    安装完成后在最后会显示root密码

    image

    拷贝可执行配置文件

    cd /usr/local/mysql
    cp ../support-files/mysql.server /etc/init.d/mysqld
    
    
    5、配置过程

    MySQL配置文件/etc/my.cnf中内容如下:

    [mysqld]
    port = 3306
    basedir = /usr/local/mysql
    datadir=/usr/local/mysql/data
    socket=/tmp/mysql.sock
    pid-file=/usr/local/mysql/data/mysql.pid
    log-error=/usr/local/mysql/data/error.log
    character_set_server=utf8
    user=mysql
    max_connections=1500
    symbolic-links=0
    # 东八区时区,北京时区
    default-time-zone = '+8:00'
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    # 导入包允许的大小设置
    max_allowed_packet=1024M
    # 忽略表名大小写;1表示忽略大小写,0表示解析大小写
    lower_case_table_names=1
    
    !includedir /etc/my.cnf.d
    
    
    6、启动服务并登陆

    常用命令

    # 启动命令
    service mysqld start 或者 /etc/init.d/mysqld start
    # 停止命令
    service mysqld stop 或者 /etc/init.d/mysqld stop
    # 重启命令
    service mysqld restart 或者 /etc/init.d/mysqld restart
    
    
    image

    登陆命令

    ./bin/mysql -u root -p'zisTBE)I8*/0'
    
    
    7、修改密码并允许远程连接
    mysql> set password=password('123456');
    mysql> use mysql;
    mysql> update user set host='%' where user='root';
    mysql> flush privileges;
    
    

    如果远程还连接不上,看下是否防火墙开启了?

    8、添加环境变量
    vim /etc/profile
    
    # mysql
    PATH=/usr/local/mysql/bin:$PATH
    
    
    image

    保存退出后,使用source /etc/profile使其生效。

    三、MySQL自启

    # 查看MySQL是否自启
    systemctl is-enabled mysqld
    
    

    如下图,显示disabled,MySQL默认非自启

    image
    # 开启自启
    systemctl enable mysqld
    
    

    如下图

    image

    四、防火墙放行3306端口

    如果你的防火墙已经关闭,可忽略此操作。

    # 永久开放3306端口
    firewall-cmd --permanent --zone=public --add-port=3306/tcp
    # 重启防火墙
    systemctl restart firewalld
    # 检测设定是否生效
    iptables -nL | grep 3306
    
    

    五、其他问题

    问题1:yum仓库无法更新问题

    在使用yum repolist列出仓库中的包时,出现Error: Failed to synchronize cache for repo 'AppStream'
    由于其原有的默认的源配置文件被我删除过,然后CentOS8换过阿里的源,在卸载MySQL8之后重新安装后出现上述问题;解决参照:CentOS8使用阿里源

    将原来文件中$releasever替换为8.0.1905,将$basearch替换为x86_64,然后再使用yum clean all && yum makecache即可

    正常的CentOS-Base.repo内容如下

    # CentOS-Base.repo
    #
    # The mirror system uses the connecting IP address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client.  You should use this for CentOS updates
    # unless you are manually picking other mirrors.
    #
    # If the mirrorlist= does not work for you, as a fall back you can try the 
    # remarked out baseurl= line instead.
    #
    #
    
    [base]
    name=CentOS-8.0.1905 - Base - mirrors.aliyun.com
    failovermethod=priority
    baseurl=https://mirrors.aliyun.com/centos/8.0.1905/BaseOS/x86_64/os/
            http://mirrors.aliyuncs.com/centos/8.0.1905/BaseOS/x86_64/os/
            http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/BaseOS/x86_64/os/
    gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
    
    #additional packages that may be useful
    [extras]
    name=CentOS-8.0.1905 - Extras - mirrors.aliyun.com
    failovermethod=priority
    baseurl=https://mirrors.aliyun.com/centos/8.0.1905/extras/x86_64/os/
            http://mirrors.aliyuncs.com/centos/8.0.1905/extras/x86_64/os/
            http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/extras/x86_64/os/
    gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
    
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-8.0.1905 - Plus - mirrors.aliyun.com
    failovermethod=priority
    baseurl=https://mirrors.aliyun.com/centos/8.0.1905/centosplus/x86_64/os/
            http://mirrors.aliyuncs.com/centos/8.0.1905/centosplus/x86_64/os/
            http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/centosplus/x86_64/os/
    gpgcheck=1
    enabled=0
    gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
    
    [PowerTools]
    name=CentOS-8.0.1905 - PowerTools - mirrors.aliyun.com
    failovermethod=priority
    baseurl=https://mirrors.aliyun.com/centos/8.0.1905/PowerTools/x86_64/os/
            http://mirrors.aliyuncs.com/centos/8.0.1905/PowerTools/x86_64/os/
            http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/PowerTools/x86_64/os/
    gpgcheck=1
    enabled=0
    gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
    
    [AppStream]
    name=CentOS-8.0.1905 - AppStream - mirrors.aliyun.com
    failovermethod=priority
    baseurl=https://mirrors.aliyun.com/centos/8.0.1905/AppStream/x86_64/os/
            http://mirrors.aliyuncs.com/centos/8.0.1905/AppStream/x86_64/os/
            http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/AppStream/x86_64/os/
    gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
    

    作者:静美书斋
    链接:https://www.jianshu.com/p/ee018b20a6e6
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    本人遇到的问题:
    tar -zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

    ln -s mysql-5.7.32-linux-glibc2.12-x86_64/ mysql

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

    错误:
    error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
    解决办法:
    ln -s /usr/lib64/libncurses.so.6.1 /usr/lib64/libncurses.so.5

    错误:
    error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
    解决办法:
    ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

    alter user 'root'@'localhost' identified by 'bpm,.123';

    相关文章

      网友评论

          本文标题:CentOS8安装mysql-5.7.32

          本文链接:https://www.haomeiwen.com/subject/qbvkcltx.html