美文网首页
CentOS 7.4 64bit 安装mysql-5.7.24-

CentOS 7.4 64bit 安装mysql-5.7.24-

作者: 冥鳴明铭 | 来源:发表于2018-11-23 17:06 被阅读0次

    作者:王树民ITDATA
    原文:https://blog.csdn.net/wangshuminjava/article/details/80873984

    一、检查并卸载MYSQL插件

    rpm -qa | grep -i mysql
    

    如果有不需要的插件执行卸载

    rpm -ev ***
    

    查找老版本mysql相关的安装目录

    find / -name mysql
    

    有则删除

    rm -rf /usr/share/mysql
    rm -rf /usr/lib64/mysql
    rm -rf /etc/selinux/targeted/active/modules/100/mysql
    

    最后使用命令:rpm -qa | grep -i mysql 检查系统中是否安装mysql

    二、安装

    shell> cd /usr/local  
    shell> groupadd mysql  
    shell> useradd -g mysql mysql  
    shell> tar xzvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz  
    shell> cd mysql-5.7.20-linux-glibc2.12-x86_64  
    

    这里注意了,以前的版本是有一个my.cnf文件,这个版本不要这个了
    如果存在就把它删除吧,否则会出现各种错误

    shell> rm -rf /etc/my.cnf    
    
    shell> cd /usr/local  
    shell> ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql  
    shell> cd /usr/local/mysql  
    shell> chown -R mysql .  
    shell> chgrp -R mysql .  
    shell> mkdir /usr/local/mysql/data  
    shell> /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  
    # 出现以下几个[Warning]不用管它,只要没有[ERROR] 就是安装成功了  
    [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).  
    [Warning] InnoDB: New log files created, LSN=45790  
    [Warning] InnoDB: Creating foreign key constraint system tables.  
    [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a4d71248-c432-11e7-8eab-00163e002e4a.  
    [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.  
    [Note] A temporary password is generated for root@localhost: =MqLUlnme6hh  
    

    注意了,上面最后一行产一个随机密码,冒号后面的都是密码,我的密码则是=MqLUlnme6hh
    这个随机密码第一次登录的时候需要用到

    shell> chown -R root .  
    shell> chown -R mysql data  
    

    启动MySQL

    shell> cd /usr/local/mysql  
    shell> bin/mysqld_safe --user=mysql &  
    

    登录并更改密码

    shell> /usr/local/mysql/bin/mysql -uroot -p  
    

    这时提示输入password,输入上面的随机密码
    用随机密码登录后,必须要更改密码,否则不能进行任何操作,更改密码

    mysql> SET PASSWORD = PASSWORD('newpasswd');  
    mysql> exit;  
    

    关闭MySQL服务,输入密码回车就关闭数据库

    shell> /usr/local/mysql/bin/mysqladmin -u root -p shutdown  
    shell> Enter password:  
    

    编辑PATH搜索路径

    shell> vi /etc/profile  
    

    在profile文件末尾增加两行

    PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH  
    export PATH  
    

    使PATH搜索路径立即生效:

    shell> source /etc/profile  
    

    开机自动启动:

    shell> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql  
    shell> chkconfig --add mysql  
    

    手动启动:以root身份执行:

    shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &  
    

    登录mysql,赋予root用户所有权限,远程登录密码是123456

    grant all privileges on *.* to 'root' @'%' identified by '123456';  
    

    开放3306端口并重启防火墙

    firewall-cmd --permanent --add-port=3306/tcp  
    firewall-cmd --reload</code>  
    

    相关文章

      网友评论

          本文标题:CentOS 7.4 64bit 安装mysql-5.7.24-

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