zoukankan      html  css  js  c++  java
  • Linux下mysql创建用户并设置权限,设置远程连接

    为了安全考虑,OneinStack仅允许云主机本机(localhost)连接数据库,如果需要远程连接数据库,需要如下操作:
    打开iptables 3306端口

    # iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
    # service iptables save //保存iptables规则

    # iptables -nvL //查看端口开启情况

    =======================================================================================
    root用户登录mysql   mysql5.7版本使用
    mysql>create database SubAccount;
    mysql>GRANT ALL PRIVILEGES ON SubAccount.* TO drcloudapi@"%" IDENTIFIED BY "123456" WITH GRANT OPTION;  // *.*表示所有库的所有表
    mysql>flush privileges;
    mysql>use SubAccount;

    =================================================================================

    mysql5.7版本password已经改为authentication_string

    insert into mysql.user(Host,User,authentication_string) values("%","zizhanghu",password("123456")); //<=5.1版本能用
    //GRANT ALL PRIVILEGES ON SubAccount.* TO zizhanghu@"%" IDENTIFIED BY "123456" WITH GRANT OPTION;
    //为用户创建一个数据库(SubAccount):
    mysql>create database SubAccount;
    //授权yanzm用户拥有SubAccount数据库的所有权限(某个数据库的所有权限):
    mysql>grant all privileges on SubAccount.* to zizhanghu@'%' identified by '123456';
    //刷新系统权限表
    mysql>flush privileges;
    mysql>use SubAccount;

  • 相关阅读:
    数据类型
    32个关键字
    标识符
    Xcode常用快捷键
    Linux中级之keepalived配置
    linux中级之keepalived概念
    Linux中级之lvs三个模式的图像补充(nat,dr,tun)
    linux中级之防火墙的数据传输过程
    Linux中级之netfilter/iptables应用及补充
    linux中级之lvs配置(命令)
  • 原文地址:https://www.cnblogs.com/liruning/p/6020144.html
Copyright © 2011-2022 走看看