RHEL7 use of domestic sources yum install Mariadb 10.2.25, and configure the character set for utf8mb4

目前阿里, 清华,163等镜像站的Mariadb都是5.5的,有些项目需要用到更新的版本,所以顺便安装一下10版本的,并记录过程
  • Add USTC source of Mariadb 10.2.25 yum, and yum install

    [mariadb]
    name = MariaDB
    baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64
    gpgkey = https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    # 需要重新生成yum 缓存,再安装
    yum clean all
    yum makecache all
    # 安装mariadb客户端,服务端
    yum install mariadb-server mariadb -y
    # 启动
    systemctl start mariadb  #启动 MariaDB
    systemctl enable mariadb  #设置开机启动
  • Initialization ago Note

    在确认 MariaDB 数据库软件程序安装完毕并成功启动后请不要立即使用。为了确保数据 库的安全性和正常运转,需要先对数据库程序进行初始化操作。这个初始化操作涉及下面 5 个 步骤。
    ➢ 设置 root 管理员在数据库中的密码值(注意,该密码并非 root 管理员在系统中的密 码,这里的密码值默认应该为空,可直接按回车键)。
    ➢ 设置 root 管理员在数据库中的专有密码。
    ➢ 随后删除匿名账户,并使用 root 管理员从远程登录数据库,以确保数据库上运行的业
    务的安全性。
    ➢ 删除默认的测试数据库,取消测试数据库的一系列访问权限。
    ➢ 刷新授权列表,让初始化的设定立即生效。
  • Initialization Commands

    mysql_secure_installation   # 确保mariadb服务器启动后,执行
  • Mariadb amended as Chinese coding and with immediate effect and permanently preserved, the following two stages

  • Modification (restart failure) database running

    # 在mariadb命令中设置
    MariaDB [(none)]>  SET NAMES 'utf8mb4';
    MariaDB [(none)]>  set character_set_server = utf8mb4;set character_set_database = utf8mb4;set collation_database = utf8mb4_general_ci ;set collation_server = utf8mb4_general_ci ;
  • Permanent modification, /etc/my.cnf

    [client-server]
    [mysqld]
    character-set-server=utf8mb4
    collation-server=utf8mb4_unicode_ci
    log-error=/var/log/mysqld.log
    init-connect='SET NAMES utf8mb4'
    [client]
    default-character-set=utf8mb4
    [mysql]
    default-character-set=utf8mb4
  • Restart mariadb

    # stop关闭 mariadb,再start开启才生效, restart重启不行
    systemctl stop mariadb
    systemctl start mariadb
    # 查看修改后的字符编码集,已改为 utf8mb4
    show variables like "%character%";show variables like "%collation%";
    # 如果你的数据库中已经存在表了,建议进行修复一下
    mysqlcheck -u root -p --auto-repair --optimize --all-databases
  • mariadb basic commands

    # 1 远程链接mysql服务端
    mysql -uroot -p -h 192.168.1.2
    # 2 修改mysql密码
    MariaDB [(none)]> set password = PASSWORD('redhat123');
    # 3 创建mysql用户
    create user xiaochun@'%' identified by 'pw666';
    # 4 查询mysql库中的用户信息
    use mysql;
    select host,user,password from  user;
    # 5 创建数据库
    MariaDB [(none)]> create database demo
    # 6 创建表
    MariaDB [root]> create table test(id int,name char(32));
  • Database permissions

    mysql使用grant命令对账户进行授权,grant命令常见格式如下
    grant 权限 on 数据库.表名 to 账户@主机名            对特定数据库中的特定表授权
    grant 权限 on 数据库.* to 账户@主机名              对特定数据库中的所有表给与授权
    grant 权限1,权限2,权限3 on *.* to 账户@主机名      对所有库中的所有表给与多个授权
    grant all privileges on *.* to 账户@主机名      对所有库和所有表授权所有权限
    [例]
    # 1 授予×××创建的权限,对于所有的库表生效
    grant create  on *.* to xiaoming@"%"  identified by 'xc666';
    # 2 授予×××用户,只有创建mymysql数据库的权限
    grant create  on mymysql.* to xiaoming@"%"  identified by 'xc666';
    # 3 授予用户最大的权限,所有的权限
    grant all privileges on *.* to username@'%' identified by 'password';
    # 4 移除权限
    MariaDB [(none)]> revoke all privileges on *.* from xiaoming@"%" identified by 'xc666';
  • Backup and restore databases

    # 数据库命令备份
    mysqldump -u root -p --all-databases > /tmp/db.sql
    # 数据导入,方式有2种
    source /tmp/db.sql;
    或者
    mysql -uroot -p <  /tmp/db.sql 
    # 其他的备份工具
    navicat
    # 如果你数据量特别大的话,使用第三方工具
    xtrabackup

Guess you like

Origin blog.51cto.com/dldxzjr/2425788