Mysql创建数据库以及用户的权限分配 您所在的位置:网站首页 mysql添加新用户并远程连接服务器 Mysql创建数据库以及用户的权限分配

Mysql创建数据库以及用户的权限分配

2024-07-01 21:58| 来源: 网络整理| 查看: 265

Mysql创建数据库以及用户的权限分配 一、Docker创建Mysql容器二、Mysql创建数据库以及用户分配权限三、参考链接 前言:如果你并没有用Docker,可以直接跳到2.2 ,问题核心

一、Docker创建Mysql容器

请点下方链接 Docker创建Mysql容器 - https://blog.csdn.net/weixin_45941687/article/details/119672219

二、Mysql创建数据库以及用户分配权限

2.1 在Docker容器,首先进去mysql容器

# 查看容器列表 [root@localhost ~]# docker ps #进入容器 [root@localhost ~]# docker exec -it a0e96ba04013 bash root@a0e96ba04013:/#

2.2 创建数据库 并分配权限

# 1.登录 [root@localhost ~]# docker exec -it a0e96ba04013 bash root@a0e96ba04013:/# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.23 MySQL Community Server - GPL Copyright (c) 2000, 2021, 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. # 2.查看当前数据库 - (用什么user登录,只能查到对应权限的信息) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.03 sec) # 3.创建名称为“qtww”数据库,并设定编码集为utf8 mysql> CREATE DATABASE IF NOT EXISTS qtww DEFAULT CHARSET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected, 2 warnings (0.02 sec) # 4.创建用户名为(qtwwname)密码为(123456),自己的账户可以创建相对复杂的密码,保存好别忘记了 mysql> create user 'qtwwname'@'%' identified by '123456'; Query OK, 0 rows affected (0.03 sec) 注意: 此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。 # 5. 查询用户 mysql> select user,host from mysql.user; +------------------+-----------+ | user | host | +------------------+-----------+ | qtwwname | % | | root | % | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 8 rows in set (0.00 sec) # 6.授予权限 # 6.1 授予用户通过外网IP对于该数据库“qtww”的全部权限 # 如果是给全部数据库的权限 grant all privileges on *.* to 'qtwwname'@'%'; mysql> grant all privileges on qtww.* to 'qtwwname'@'%'; Query OK, 0 rows affected (0.02 sec) # 6.2 授予用户“qtwwname”用户通过外网IP对于该数据库“qtww”中表的创建、修改、删除权限,以及表数据的增删查改权限 grant create,alter,drop,select,insert,update,delete on qtww.* to 'qtwwname'@'%'; # 7 刷新权限 mysql> flush privileges; Query OK, 0 rows affected (0.03 sec) # 8 查看用户“qtwwname” mysql> show grants for 'qtwwname'@'%'; +----------------------------------------------------+ | Grants for qtwwname@% | +----------------------------------------------------+ | GRANT USAGE ON *.* TO `qtwwname`@`%` | | GRANT ALL PRIVILEGES ON `qtww`.* TO `qtwwname`@`%` | +----------------------------------------------------+ 2 rows in set (0.01 sec) 三、参考链接

https://www.cnblogs.com/wuyunblog/articles/8288267.html

https://blog.csdn.net/qq_38328378/article/details/80858073



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有