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)
  • 相关阅读:
    修改Sharepoint 文档库列表点击Excel文件默认跳转到Excel Service服务 xlviewer.aspx页面
    记一次TSQL查询优化 索引的重要性
    使用Uploadify 时,同时使用了jQuery.Validition 验证控件时,在IE11上出现JS缺少对象错误。
    Visual Studio 2015开发Android App问题集锦
    ASP.Net + SQL Server 存储过程实现分页排序
    JotSpot,是什么尤物?(Google收购JotSpot)
    Google创始人之一天才Larry Page呼吁:做研究的人要重视市场营销
    Google Base API - GData 发布
    品尝SPARQL系列之一 SPARQL over HTTP/SOAP -- Joseki引擎的配置和示例程序
    万维网之父Tim BernersLee在美国国会公听会上再谈Web发展的愿景-语义网
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/12066237.html
Copyright © 2011-2022 走看看