zoukankan      html  css  js  c++  java
  • Mysql添加用户与授权

    1.以root用户登录Mysql

    mysql -uroot -proot

    2.切换到mysql数据库

    use mysql

    3.添加用户

    //只允许指定ip连接
    create user '新用户名'@'localhost' identified by '密码';
    //允许所有ip连接(用通配符%表示)
    create user '新用户名'@'%' identified by '密码';

    4.为新用户授权

    //基本格式如下
    grant all privileges on 数据库名.表名 to '新用户名'@'指定ip' identified by '新用户密码' ;
    //示例
    //允许访问所有数据库下的所有表
    grant all privileges on *.* to '新用户名'@'指定ip' identified by '新用户密码' ;
    //指定数据库下的指定表
    grant all privileges on test.test to '新用户名'@'指定ip' identified by '新用户密码' ;

    5.设置用户操作权限

    //设置用户拥有所有权限也就是管理员
    grant all privileges on *.* to '新用户名'@'指定ip' identified by '新用户密码' WITH GRANT OPTION;
    //拥有查询权限
    grant select on *.* to '新用户名'@'指定ip' identified by '新用户密码' WITH GRANT OPTION;
    //其它操作权限说明,select查询 insert插入 delete删除 update修改
    //设置用户拥有查询插入的权限
    grant select,insert on *.* to '新用户名'@'指定ip' identified by '新用户密码' WITH GRANT OPTION;
    //取消用户查询的查询权限
    REVOKE select ON what FROM '新用户名';

    6.删除用户

    DROP USER username@localhost;

    7.修改后刷新权限

    FLUSH PRIVILEGES;

    创建用户可能报错

    ERROR 1805 (HY000): Column count of mysql.user is wrong

    解决方法:
    使用mysql_upgrade升级数据库的用户表。

    mysql_upgrade -uroot -proot
  • 相关阅读:
    VC++:创建,调用Win32静态链接库
    VC++:创建,调用Win32动态链接库
    C++生成和解析XML文件
    C++实现16进制字符串转换成int整形值
    一个好隐蔽的C/C++代码bug
    【C++札记】标准模板库string
    Rabbitmq C++客户端 Rabbitmq Client
    C++:标准模板库map
    C++:标准模板库vector
    C++:标准模板库(STL)
  • 原文地址:https://www.cnblogs.com/418836844qqcom/p/12119470.html
Copyright © 2011-2022 走看看