美文网首页
Linux离线安装MySQL5.7

Linux离线安装MySQL5.7

作者: MaJiT | 来源:发表于2020-09-30 12:23 被阅读0次

    1.卸载Linux自带的mariadb

    //查看
    rpm -qa | grep mysql
    rpm -qa | grep mariadb
    //卸载
    rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
    // 删除etc目录下的my.cnf
    rm /etc/my.cnf
    

    2.检查mysql组和用户是否存在,如无则创建

    # 检查mysql组和用户是否存在
     cat /etc/group | grep mysql
     cat /etc/passwd | grep mysql
    # 创建mysql用户组
    groupadd mysql
    # 创建一个用户名为mysql的用户,并加入mysql用户组
    useradd -g mysql mysql
    # 制定password 为1234
     passwd mysql
    #我的密码时Mysql@1234
    

    3.下载好的安装包拷贝到/usr/local 并解压

    4.更改所属的组和用户

     cd /usr/local/
     chown -R mysql mysql/
     chgrp -R mysql mysql/
    cd mysql/
    mkdir data
    chown -R mysql:mysql data
    

    5.在/etc下创建my.cnf文件

    [mysql]
    socket=/var/lib/mysql/mysql.sock
    # set mysql client default chararter
    default-character-set=utf8
    
    [mysqld]
    socket=/var/lib/mysql/mysql.sock
    # set mysql server port  
    port = 3306#默认是3306
    # set mysql install base dir
    basedir=/usr/local/mysql
    # set the data store dir
    datadir=/usr/local/mysql/data
    # set the number of allow max connnection
    max_connections=200
    # set server charactre default encoding
    character-set-server=utf8
    # the storage engine
    default-storage-engine=INNODB
    lower_case_table_names=1
    max_allowed_packet=16M
    explicit_defaults_for_timestamp=true
    
    [mysql.server]
    user=mysql
    basedir=/usr/local/mysql
    

    6.进入mysql文件夹,并安装mysql

    cd /usr/local/mysql
    bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
    cp ./support-files/mysql.server /etc/init.d/mysqld
    chown 777 my.cnf
    chmod +x /etc/init.d/mysqld
    

    7.启动mysql

    /etc/init.d/mysqld restart
    

    8.设置开机启动

    chkconfig --level 35 mysqld on
    chkconfig --list mysqld
    chmod +x /etc/rc.d/init.d/mysqld
    chkconfig --add mysqld
    chkconfig --list mysqld
    service mysqld status
    

    9.修改配置文件

     vim /etc/profile
    修改/etc/profile,在最后添加如下内容
    export PATH=$PATH:/usr/local/mysql/bin
    

    10.获得mysql初始密码并修改

    //获取初始密码
    cat /root/.mysql_secret
    //登录  
    mysql -uroot -p
    //修改密码
    set PASSWORD = PASSWORD('123456');
    flush privileges;
    exit
    

    11.添加远程访问权限

    //登录  
    mysql -uroot -p
    use mysql
    update user set host='%' where user='root';
    

    12.重启

    /etc/init.d/mysqld restart
    

    相关文章

      网友评论

          本文标题:Linux离线安装MySQL5.7

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