zoukankan      html  css  js  c++  java
  • mysql新增用户

      新开了个项目,数据库也想新搞个用户,先登陆mysql,看看原来都有哪些:

    root@wlf:/# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 76766
    Server version: 5.7.26-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> select host,user from mysql.user;
    +-----------+---------------+
    | host      | user          |
    +-----------+---------------+
    | %         | backup        |
    | %         | hellodevelop     |
    | %         | hellocloud       |
    | %         | passerby      |
    | %         | hellomg         |
    | localhost | mysql.session |
    | localhost | mysql.sys     |
    | localhost | root          |
    +-----------+---------------+
    8 rows in set (0.00 sec)

      我们新增一个prize用户:

    mysql> create user 'prize'@'%' identified by 'prize';
    Query OK, 0 rows affected (0.11 sec)
    
    mysql> select host,user from mysql.user;
    +-----------+---------------+
    | host      | user          |
    +-----------+---------------+
    | %         | backup        |
    | %         | hellodevelop     |
    | %         | hellocloud       |
    | %         | passerby      |
    | %         | prize         |
    | %         | hellomg         |
    | localhost | mysql.session |
    | localhost | mysql.sys     |
    | localhost | root          |
    +-----------+---------------+
    9 rows in set (0.00 sec)

      

      但这会儿新用户是没有任何操作权限的,除了看看:

    mysql> show grants for 'prize'@'%';
    +-----------------------------------+
    | Grants for prize@%                |
    +-----------------------------------+
    | GRANT USAGE ON *.* TO 'prize'@'%' |
    +-----------------------------------+
    1 row in set (0.00 sec)

      

      所以我们还得给它赋予各种权限:

    mysql> grant all privileges on `prize`.* to 'prize'@'%';
    Query OK, 0 rows affected (0.04 sec)
    
    mysql> show grants for 'prize'@'%';
    +--------------------------------------------------+
    | Grants for prize@%                               |
    +--------------------------------------------------+
    | GRANT USAGE ON *.* TO 'prize'@'%'                |
    | GRANT ALL PRIVILEGES ON `prize`.* TO 'prize'@'%' |
    +--------------------------------------------------+
    2 rows in set (0.00 sec)

      刷新一下权限:

    mysql> flush privileges;
    Query OK, 0 rows affected (0.09 sec)

      现在可以进入prize用户开始我们的倒腾了:

    mysql> exit;
    Bye
    root@d5afa9102517:/# mysql -uprize -pprize
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 77055
    Server version: 5.7.26-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> create database prize;
    Query OK, 1 row affected (0.09 sec)
  • 相关阅读:
    JAVA练习3
    JAVA练习2
    找出一个整型数组中元素最大值,使用面向对象方法
    类和对象应用例题
    用指针变量作函数形参接收数组地址,解决10个整数按由大到小顺序排序问题
    把指针作为函数参数的方法处理从大到小排序问题。
    通过指针变量访问整型变量
    用选择法对数组中10个整数进行排列
    有参函数的调用
    函数模板
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/12066237.html
Copyright © 2011-2022 走看看