美文网首页
centos 安装 MySQ8.0

centos 安装 MySQ8.0

作者: 阳光也学会了妩媚 | 来源:发表于2020-12-14 09:37 被阅读0次

    rpm -qa|grep -i mysql

    rpm -ev --nodeps mysql-community-release-el7-5.noarch
    rpm -ev --nodeps mysql-community-common-5.6.38-2.el7.x86_64
    rpm -ev --nodeps mysql-community-client-5.6.38-2.el7.x86_64
    rpm -ev --nodeps mysql-community-libs-5.6.38-2.el7.x86_64
    rpm -ev --nodeps community-server-5.6.38-2.el7.x86_64

    find / -name mysql

    rm -rf 上面查出的文件夹

    etc/my.cnf 如果存在的话手动删除,这样mysql就卸载完成了。

    centos的yum 源中默认是没有mysql的,所以我们需要先去官网下载mysql的repo源并安装;
    网址:https://dev.mysql.com/downloads/repo/yum/ 操作如下:

    wget http://dev.mysql.com/get/Downloads/mysql80-community-release-el7-1.noarch.rpm

    安装 yum repo文件并更新 yum 缓存

    rpm -ivh mysql57-community-release-el7-11.noarch.rpm

    会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo mysql-community-source.repo
    更新 yum 命令

    yum clean all
     
    yum makecache
    

    查看mysql yum仓库中mysql版本,使用如下命令

    yum repolist all | grep mysql

    使用 yum-config-manager 命令修改相应的版本为启用状态最新版本为禁用状态

    yum-config-manager --disable mysql80-community
     
    yum-config-manager --enable mysql57-community
    

    安装mysql 命令如下:

    yum install mysql-community-server

    开启mysql 服务

    systemctl start mysqld.service

    systemctl start mysqld.service
    systemctl restart mysqld
    systemctl status mysqld.service

    /etc/rc.d/init.d/mysqld: line 239: my_print_defaults: command not found
    /etc/rc.d/init.d/mysqld: line 259: cd: /usr/local/mysql: No such file or directory
    Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

    my.cnf

    [root@izm5eafr6zh39w6kuias38z /]# cd ext
    -bash: cd: ext: No such file or directory
    [root@izm5eafr6zh39w6kuias38z /]# cd etc
    [root@izm5eafr6zh39w6kuias38z etc]# cat my.cnf

    For advice on how to change settings please see

    http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

    [mysqld]

    Remove leading # and set to the amount of RAM for the most important data

    cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

    innodb_buffer_pool_size = 128M

    Remove the leading "# " to disable binary logging

    Binary logging captures changes between backups and is enabled by

    default. It's default setting is log_bin=binlog

    disable_log_bin

    Remove leading # to set options mainly useful for reporting servers.

    The server defaults are faster for transactions and fast SELECTs.

    Adjust sizes as needed, experiment to find the optimal values.

    join_buffer_size = 128M

    sort_buffer_size = 2M

    read_rnd_buffer_size = 2M

    Remove leading # to revert to previous value for default_authentication_plugin,

    this will increase compatibility with older clients. For background, see:

    https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin

    default-authentication-plugin=mysql_native_password

    mysql安装根目录

    basedir = /usr/local/mysql

    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock

    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    [root@izm5eafr6zh39w6kuias38z etc]#

    //查看默认密码
    grep 'temporary password' /var/log/mysqld.log
    //修改密码 
    ALTER user 'root'@'localhost' IDENTIFIED BY 'root123456';

    创建用户并指定多IP访问

    1. 创建用户并设置密码模式

      CREATE USER '用户名'@'IP' IDENTIFIED WITH mysql_native_password BY '密码';

    2.给创建的账号赋权
    
       GRANT ALL PRIVILEGES ON *.* TO '用户名'@'ip';
    
       如果需要指定权限,就将ALL改为SELECT DELETE UPDATE INSERT等四种权限任选即可
    
    3.如果还需要设置到另一个ip, 那么就需要重复上面的步骤:
    
        虽然是重复步骤,但是用户名、密码保持和上面一致,ip改变就可以了
    
         CREATE USER '用户名'@'IP' IDENTIFIED WITH mysql_native_password BY '密码';
    
         GRANT ALL PRIVILEGES ON *.* TO '用户名'@'ip';
    
    4.如果创建错了,可以使用下面语句删除用户:
        drop user '用户名'@'ip';
    
        删除指定ip的用户

    相关文章

      网友评论

          本文标题:centos 安装 MySQ8.0

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