Centos7安装mysql8

1. 官网下载linux-generic通版本

   执行:wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz

2. 解压安装以及相关细节

     //MySQL has a dependency on the libaio library
    //检查依赖包
    yum search libaio  # search for info
    yum install libaio # install library
    // 添加一个用户组
    groupadd mysql
    //创建mysql用户并加入mysql组
    useradd -r -g mysql -s /bin/false mysql
    // 解压文件
    cd /usr/local
    tar zxvf mysql-VERSION-OS.tar.gz
    mv mysql-VERSION-OS.tar.gz mysql
    // 创建一个连接,(可选)
    ln -s full-path-to-mysql-VERSION-OS mysql
    // chown命令改变某个文件或目录的所有者和所属的组
    cd mysql
    chown -R root:root ./
    chown -R mysql:mysql data
    // 初始化
    bin/mysqld --initialize --user=mysql
    // 开启加密连接
    bin/mysql_ssl_rsa_setup
    // 启动
    /usr/local/mysql/support-files/mysql.server start

3.配置文件(根据需要配置)

  发现没有my.cnf可以自己创建,并放在/etc中

  user=mysql
  character_set_server = utf8
  basedir=/usr/local/mysql
  datadir=/usr/local/mysql/data
  pid-file=/usr/local/mysql/data/iz2ze2t0ob6ppkgpmww0unz.pid
  log-error=iz2ze2t0ob6ppkgpmww0unz.err

4. 问题解决

  1).root无法登陆

    原因:mysql8使用新的加密规则caching_sha2_password (之前使用的是mysql_native_password) 同事废弃了密码字段password改用authentication_string

   解决:启动时跳过验证: ./mysqld_safe --skip-grant-tables &(不是后台程序) ,然后回车后登陆root(无密码) ,置空root的authentication_string字段,再修改密码

                 update user set authentication_string='' where user='root';

       alter user 'root'@'%' dentified by  'newPassword';(不要用update,因为authentication_string字段下只能是mysql加密后的41位字符串密码)

                 (或者在my.cnf中加入skip-grant-tables登陆root)

       2)客服端远程连接错误: authentication plugin 'caching_sha2_password'

           原因:还是因为mysql8新的加密规则

    解决:第一种 修改配置文件my.cnf 加入

         default_authentication_plugin=mysql_native_password

       第二种专门创建一个以前版本的规则的账号,用于远程连接(官方推荐)

                        create user 'your username'@'%' identified with mysql_native_password by 'your password'

       grant all privileges on *.* to chenadmin@'%' with grant option;

       flush privileges

       3)删除用户之后,重新创建失败

    delete之后,flush privileges。不行的话,重新drop一遍,再flush privileges

修改当前目录拥有者为root用户:执行命令 chown -R root:root ./

修改当前data目录拥有者为mysql用户:执行命令 chown -R mysql:mysql data

猜你喜欢

转载自www.cnblogs.com/laoyin666/p/9278645.html