余温旧梦-王世彪的博客
关注公众号
  • 开发桌面程序
  • javascript教程
  • css样式
  • vuejs
  • 部署免费CDN
  • SEO搜索引擎优化
  • vuepress教程
  • redis分布式缓存
  • Golang
  • PHP
  • Python
  • Java
  • NodeJs
  • tomcat
  • ELK
  • Mysql数据库
  • Nosql数据库
  • C/C++底层开发
  • 音视频/流媒体
  • linux服务器
  • nginx服务器
  • 容器技术
  • 负载均衡
  • 项目管理
  • 持续集成
  • 大数据
  • 微信公众号运营
  • markdown用法
赞一个
友链
联系作者

王世彪

努力做个影响他人滴人
关注公众号
  • 开发桌面程序
  • javascript教程
  • css样式
  • vuejs
  • 部署免费CDN
  • SEO搜索引擎优化
  • vuepress教程
  • redis分布式缓存
  • Golang
  • PHP
  • Python
  • Java
  • NodeJs
  • tomcat
  • ELK
  • Mysql数据库
  • Nosql数据库
  • C/C++底层开发
  • 音视频/流媒体
  • linux服务器
  • nginx服务器
  • 容器技术
  • 负载均衡
  • 项目管理
  • 持续集成
  • 大数据
  • 微信公众号运营
  • markdown用法
赞一个
友链
联系作者
  • 分布式缓存

  • 分布式存储

  • mysql

    • mysql创建数据库指定编码
    • mysql的事务及事务隔离级别
    • sql审核平台Archery的安装和使用
    • 修改mysql列定义
    • mysql创建用户
      • 1. 创建用户
      • 2. 授权
      • 3. 验证
    • mysql 常用 json 函数
    • mysql类型转换函数
    • mysql为1张表同时添加多个字段
    • mysql为大表增加字段
  • postgresql

  • mongodb

  • c或c++

  • golang

  • php

  • java

  • nodejs

  • python

  • tomcat

  • elk

  • 音视频流媒体

  • 后台
  • mysql
王世彪
2022-04-09
目录

mysql创建用户

# mysql创建用户

本文介绍mysql如何创建用户,mysql低版本和8.0以后版本的操作方法略有不同。低版本的grant命令支持自动创建用户,而8.0以后版本不支持。

# 1. 创建用户

若mysql版本小于8.0,该步骤可以省略。

ubuntu@VM-0-6-ubuntu:~$ mysql -uroot -pbuzhidao -h 127.0.0.1
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 221
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
7 rows in set (0.00 sec)

mysql> create user gitea@'%' identified by 'gitea';
Query OK, 0 rows affected (0.01 sec)

# 2. 授权

授权的维度如下:

  • 哪个用户
  • 哪个数据库
  • 哪些表
  • 增加、删除、修改或查询等

示例如下:

mysql> grant all privileges on gitea.* to gitea@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)

mysql> 

# 3. 验证

ubuntu@VM-0-6-ubuntu:~$ mysql -ugitea -pgitea -h 127.0.0.1
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 224
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| gitea              |
| information_schema |
+--------------------+
2 rows in set (0.00 sec)

mysql> 

可以看出该用户只能访问到数据库gitea,说明权限配置已生效。

#mysql
上次更新: 2022-04-09 18:08:45
修改mysql列定义
mysql 常用 json 函数

← 修改mysql列定义 mysql 常用 json 函数→

最近更新
01
golang错误处理最佳实践
03-17
02
基于proto文件生成rpc接口定义文档
03-11
03
git其它
03-03
更多文章>
Theme by Vdoing | Copyright © 2019-2022 王世彪 | MIT License
冀ICP备19016776号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式