mysql数据库指定ip远程访问(设置远程连接),赋权操作
mysql数据库指定ip远程访问(设置远程连接)
远程访问mysql报错,ip不允许链接的情况:
错误号码1045
Access denied for user '用户名' @'数据库地址' (using password:YES)
1.登录
# 连接格式
mysql -h数据库服务器地址 -P端口 -u用户名 -p"密码"; # 示例
mysql -h127.0.0.1 -P3306 -uroot -p"密码"; # 简写(数据库服务器地址默认,一般是指直接在数据库服务上操作)
mysql -uroot -p"密码";
之后输入密码进行登录。
2.设置远程访问,及权限设置明
2.1,创建用户,并设置允许的远程ip访问权限
# 创建用户
create user '新用户名'@'允许的来源ip' identified by '新用户的密码';
# 查看是否创建成功
select Host,User from mysql.user; # 删除用户
drop user '用户名'@'主机';
2.2,命令解释
第一行是创建新用户(如果您想直接开放root用户则不需要新创建),其中密码是新用户的密码, 其中ip是允许远程访问的IP的值。
第二行是查看mysql系统用户表,检查新建用户是否成功。
mysql赋权操作
v8及以前:
# mysql的赋权操作(适用v8以前版本):
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘密码‘ WITH GRANT OPTION;
# 变更权限后执行刷新权限才能生效
flush privileges;
with grant option是指允许用户dba,传递其拥有的权限给其他的用户。
mysql8中应该使用:
#mysql8中应该使用:
grant all privileges on *.* to 'root'@'%' ;
【赋权命令格式解释】
GRANT:赋权命令
ALL PRIVILEGES:当前用户的所有权限
ON:介词
*.*:当前用户对所有数据库和表的相应操作权限
TO:介词
‘root’@’%’:权限赋给root用户,所有ip都能连接
IDENTIFIED BY ‘123456’:连接时输入密码,密码为123456
WITH GRANT OPTION:允许级联赋权
# 设置用户授权格式
grant 权限 on *.* to '新用户名'@'允许的来源ip'; # 示例一:指定【db_DeviceRepairMS】数据库【所有权限】给xxh用户
grant all privileges on db_DeviceRepairMS.* to xxh;
# 示例二:指定【db_DeviceRepairMS】数据库【某些权限】给xxh用户
grant select,insert,update,delete,create,execute,index,alter on db_DeviceRepairMS.* to xxh@'%';
# 设置用户授权(该示例只有“select,execute,index”这3个权限哦)
grant select,execute,index on *.* to '新用户名'@'允许的来源ip'; #刷新权限
flush privileges;
收回权限
# 收回用户someone的所有库和表的“insert”权限
revoke insert on *.* from 'someone'@'%';
# 收回用户somebody已经拥有的with grant option权限
revoke grant option on *.* from somebody;
revoke跟grant语法差不多,只需要把关键字 “to” 换成 “from” 即可,并且revoke语句中不需要跟密码设置。
注意:revoke可以回收所有权限,也可以回收部分权限。
查看权限
# 查看mysql系统所有权限
show privileges; # 查看当前用户权限
SHOW GRANTS;
# 或
SHOW GRANTS FOR CURRENT_USER;
# 或
SHOW GRANTS FOR CURRENT_USER(); # 查看某用户的全局权限
SHOW GRANTS FOR 'user'@'主机地址' ;
权限列表:
mysql> show privileges;
+-------------------------+---------------------------------------+-------------------------------------------------------+
| Privilege | Context | Comment |
+-------------------------+---------------------------------------+-------------------------------------------------------+
| Alter | Tables | To alter the table |
| Alter routine | Functions,Procedures | To alter or drop stored functions/procedures |
| Create | Databases,Tables,Indexes | To create new databases and tables |
| Create routine | Databases | To use CREATE FUNCTION/PROCEDURE |
| Create temporary tables | Databases | To use CREATE TEMPORARY TABLE |
| Create view | Tables | To create new views |
| Create user | Server Admin | To create new users |
| Delete | Tables | To delete existing rows |
| Drop | Databases,Tables | To drop databases, tables, and views |
| Event | Server Admin | To create, alter, drop and execute events |
| Execute | Functions,Procedures | To execute stored routines |
| File | File access on server | To read and write files on the server |
| Grant option | Databases,Tables,Functions,Procedures | To give to other users those privileges you possess |
| Index | Tables | To create or drop indexes |
| Insert | Tables | To insert data into tables |
| Lock tables | Databases | To use LOCK TABLES (together with SELECT privilege) |
| Process | Server Admin | To view the plain text of currently executing queries |
| Proxy | Server Admin | To make proxy user possible |
| References | Databases,Tables | To have references on tables |
| Reload | Server Admin | To reload or refresh tables, logs and privileges |
| Replication client | Server Admin | To ask where the slave or master servers are |
| Replication slave | Server Admin | To read binary log events from the master |
| Select | Tables | To retrieve rows from table |
| Show databases | Server Admin | To see all databases with SHOW DATABASES |
| Show view | Tables | To see views with SHOW CREATE VIEW |
| Shutdown | Server Admin | To shut down the server |
| Super | Server Admin | To use KILL thread, SET GLOBAL, CHANGE MASTER, etc. |
| Trigger | Tables | To use triggers |
| Create tablespace | Server Admin | To create/alter/drop tablespaces |
| Update | Tables | To update existing rows |
| Usage | Server Admin | No privileges - allow connect only |
+-------------------------+---------------------------------------+-------------------------------------------------------+
31 rows in set (0.00 sec)
注:以上结果查看自 Server version: 5.7.35-log MySQL Community Server (GPL)
更新授权时忘记密码怎么办?
授权后的密码是密文形式保存的,如果记不住之前授权时的密码,那么怎样保证覆盖后的权限跟之前的权限一致?
grant授权操作中其实不仅可以设置明文密码,也可以设置密文密码,如下:
1)grant 权限列表 on 库.表.* to '用户名'@'ip' identified by "明文密码"
2)grant 权限列表 on 库.表.* to '用户名'@'ip' identified by password "密文密码"
也就是说,在grant重置权限的时候可以用查看的密文密码当做新的密码,然后去覆盖之前的权限,这就保证了修改前后的密码一致!
参考:
mysql数据库指定ip远程访问(设置远程连接),赋权操作的更多相关文章
- mysql数据库指定ip远程访问 指定用户 指定数据库
.登录 mysql -u root -p 之后输入密码进行登陆 .权限设置及说明 .1添加远程ip访问权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168 ...
- mysql数据库指定ip远程访问
1.登录 mysql -u root -p 之后输入密码进行登陆 2.权限设置及说明 2.1添加远程ip访问权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'192. ...
- MySql数据库安装&修改密码&开启远程连接图解
相关工具下载地址: mysql5.6 链接:http://pan.baidu.com/s/1o8ybn4I密码:aim1 SQLyog-12.0.8 链接:http://pan.baidu.com/s ...
- [运维] 如何在云服务器上安装 MySQL 数据库, 并使用 Navicat 实现远程连接管理
.•●•✿.。.:*.•●•✿.。.:*.•●•✿.。.:*.•●•✿.。.:*.•●•✿.。.:*.•●•✿.。.:*.•.•●•✿.。.:*.•●•✿.。.:*.•●•✿.。.:*.•●•✿.。. ...
- MySQL设置远程连接
Window下MySQL设置开启远程连接mysql数据库 1.新建用户远程连接mysql数据库grant all on *.* to admin@'%' identified by '123456' ...
- linux 下修改mysql下root 权限来允许远程连接
MySQL默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接. 其操作简单,如下所示: 1. 进入mysql: /usr/local/mysql/bin/ ...
- mysql设置指定ip远程访问连接的方法
本文实例讲述了mysql设置指定ip远程访问连接的方法,分享给大家供大家参考.具体实现方法如下: 1. 授权用户root使用密码jb51从任意主机连接到mysql服务器: 复制代码 代码如下: GRA ...
- kali 开启Mysql设置远程连接管理
环境工具 kali2020.01 192.168.177.137 windows10物理机heidiSQL工具下载地址 https://www.heidisql.com/download.php 开启 ...
- linux下安装mysql并设置远程连接
腾讯云环境为Centos7.4 mysql版本为5.6 本次安装使用yum安装 检查是否已有mysql: yum list installed | grep mysql 下载yum源文件: wge ...
- Mysql 修改密码和设置远程连接
[参考文章]:mysql修改root密码和设置权限 1. 修改密码 1.1 set password 登录mysql set password for 用户名@localhost = password ...
随机推荐
- Nuxt.js 应用中的 schema:extend事件钩子详解
title: Nuxt.js 应用中的 schema:extend事件钩子详解 date: 2024/11/10 updated: 2024/11/10 author: cmdragon excerp ...
- Zipkin+Sleuth调用链监控集成和使用
背景与需求 跨微服务的API调用发生异常,要求快速定位出问题出在哪里. 跨微服务的API调用发生性能瓶颈,要求迅速定位出性能瓶颈. 集成 整体结构 整体机构为C/S模式,客户端(Sleuth)来监控采 ...
- Cargo deny安装指路
本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0许可协议.转载请注明来自 唯你 简介 cargo deny 是一个 Rust 工具,用于检查项目依赖项的许可证.安全性和其他合规性问题. ...
- P10681 COTS/CETS 2024 奇偶矩阵 Tablica
P10681 COTS/CETS 2024 奇偶矩阵 Tablica 来自 qnqfff 大佬的梦幻 dp. 约定 二元组 \((n,m)\) 表示一个 \(n\) 行 \(m\) 列的矩形. 不添加 ...
- 简单几步,基于云主机快速为Web项目添加AI助手
在华为开发者空间,借助华为云对话机器人服务 CBS您可以零代码创建一个大模型 RAG (Retrieval-Augmented Generation,即检索增强生成)应用,来实现 AI 助手的智能问答 ...
- docker 打包镜像过程
1.首先准备需要打成镜像的JAR包 2.编制Dockerfile文件 FROM docker.gf.com.cn/java:openjdk-8u292-arm64 MAINTAINER 8627905 ...
- Postgresql——postgis安装
PostGIS安装 PostGIS 是一个开源数据库拓展,它为 PostgreSQL 数据库增加了对地理空间数据的支持.PostGIS 使得空间数据的存储.查询和分析变得简单高效. PostGIS 是 ...
- 纯JS+CSS实现羊了个羊
前言 省流 gitee上扒的,感觉还不错,拿下来玩玩. https://gitee.com/kenxq/ylgy.git 技术说明 纯JS+CSS实现羊了个羊,包含部分特效,响应式手机.电脑.ipad ...
- AO SDK安装问题
ao sdk for .net安装时,需要进行验证.net框架,没装vs的时候会提示 arcobjects SDK for the Microsoft.NT Framework requires a ...
- vs2017 opencv 编译错误 error C2665: “exp”: 3 个重载中没有一个可以转换所有参数类型
编译错误 - error C2665: "exp": 3 个重载中没有一个可以转换所有参数类型,在GenericPacketMath.h文件, 是因为使用了Eigen3.4库,只要 ...