zoukankan      html  css  js  c++  java
  • centos6.9 安装mysql8

    centos6.9 安装 mysql8

    # 安装mysql8

    1.下载
    https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.16-2.el6.x86_64.rpm-bundle.tar

    2.解压

    tar -xvf mysql-8.0.16-2.el6.x86_64.rpm-bundle.tar

    rpm -iv mysql-community-common-8.0.16-2.el6.x86_64.rpm
    rpm -iv mysql-community-libs-8.0.16-2.el6.x86_64.rpm
    rpm -iv mysql-community-client-8.0.16-2.el6.x86_64.rp
    rpm -iv mysql-community-server-8.0.16-2.el6.x86_64.rpm

    3.启动mysql

    service mysqld status
    service mysqld start

    4.开机启动

    systemctl enable mysqld
    systemctl daemon-reload

    5.链接mysql

    查看root默认密码
    sudo grep 'temporary password' /var/log/mysqld.log

    mysql -uroot -p
    密码是上一步查询出来的。输入后回车。

    修改root密码
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ymm1234@';

    说明密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位


    6.添加远程用户登录
    选择 mysql 数据库:use mysql;

    在 mysql 数据库的 user 表中查看当前 root 用户的相关信息:

    select host, user from user;

    GRANT ALL ON *.* TO 'root'@'%';
    如果报错则使用
    update user set host='%' where user ='root';
    flush privileges;

    如果通过客户端链接时提示需要升级客户端,则使用下面的命令

    命令如下:
    1、use mysql;
    2、alter user 'root'@'%' identified with mysql_native_password by '********';
    3、flush privileges;

    7.修改配置文件
    my.cnf

    [client]
    default-character-set=utf8mb4

    [mysql]
    default-character-set=utf8mb4

    [mysqld]
    character-set-client-handshake = FALSE
    character-set-server=utf8mb4
    collation-server=utf8mb4_unicode_ci
    init_connect='SET NAMES utf8mb4'


    8.进行数据恢复(utf-8编码)
    mysql --default-character-set=utf8 -uroot -p
    Ymm1234@


    use dgds;
    source /data/downloads/dgds.sql;

    use server_sn;
    source /data/downloads/server_sn.sql;

    use server;
    source /data/downloads/server.sql;


    9.创建用户
    CREATE USER 'username'@'host' IDENTIFIED BY 'password';
    GRANT privileges ON databasename.tablename TO 'username'@'host'
    flush privileges;

    CREATE USER 'server'@'%' IDENTIFIED with mysql_native_password BY 'mySQL2019!';
    GRANT all ON *.* TO 'server'@'%';
    flush privileges;


    alter user 'server'@'%' identified with mysql_native_password by 'mySQL2019!';


    10.如果是springboot程序,不用修改为mysql-native_password ,可以直接修改链接jar包版本即可
    mysql驱动已经更新适配了caching_sha2_password 的密码规则,升级到最新版本就可以了。
    <version>8.0.11</version>


    11.具体解决方法
    解决方案有很多,我是创建了一个新用户,并指定加密规则为:mysql_native_password,这样的话,仅需要执行以下语句即可:

    create user 'your username'@'%' identified with mysql_native_password by 'your password
    也可以直接修改my配置文件,将默认密码规则设置为mysql_native_password,刷新权限并重置root密码即可。

    default_authentication_plugin=mysql_native_password
    如果想用新的caching_sha2_password也是可以的,java的话mysql已经推出了新的mysql-connector-java包,引入后,驱动使用com.mysql.cj.jdbc.driver即可,这个方案本地试了。没有问题。

  • 相关阅读:
    [LeetCode] Search a 2D Matrix
    [LeetCode] Merge Sorted Array
    [LeetCode] Remove Duplicates from Sorted Array
    [LeetCode] Convert Sorted Array to Binary Search Tree
    [LeetCode] Remove Element
    [LeetCode] Search Insert Position
    [LeetCode] Remove Duplicates from Sorted List
    [LeetCode] Merge Two Sorted Lists
    [LeetCode] Best Time to Buy and Sell Stock II
    [LeetCode] Reverse Integer
  • 原文地址:https://www.cnblogs.com/liuxm2017/p/11133485.html
Copyright © 2011-2022 走看看