当前位置:网站首页>MySQL数据库远程访问权限设置
MySQL数据库远程访问权限设置
2022-07-02 06:57:00 【软件测试小小白】
MySQL数据库远程访问权限设置
对于初学者小伙伴来说,我们安装mysql到本地服务,再用一些图形化工具链接。一般情况下我们都能链接成功;但是、在模拟真实的环境中我们的数据库不可能直接安装在本地机器上,大多数是在云服务器上,这种情况我们的mysql也不是路边大巴招手即停的,你还是要约的(先买票!);也就是你的帐号不允许从远程登陆,只能在localhost登录,怎么办?
接下来给大家讲解两种简单的方法、方法再简单要先用管理员账户登录进去,这样才可以修改
让我们先登录上mysql
一、改表(当然我们要先知道表在哪,适用于整个数据库)
• show databases;#显示所有数据库
• use mysql;#使用mysql数据库
• show tables;#找到这个user表


• select * from user;#查看该表所有信息

我们能清楚的对应的主机;用户以及用户权限
1、直接修改
update user set host = '%' where user = 'root';#更新root用户的主机访问为任何值
2、加指定用户以及指定权限
insert into user(host,user) values('ip','user');#添加一个用户user地址ip的无权限用户(可以插入新增用户信息时,附带把权限也查进去,执行时会有告警,因为表中有约束,不用深究)

新增成功,但是没有权限。
二、授权
• 直接授权(mysql8.0版本会报错,语法分割)
grant all privileges on *.* to 'user'@'ip' identified by '123456';#授权给主机为ip的user用户开放,所有数据库及对应表的所有权限,并且密码设置为123456(快速简洁)
• 直接授权(改-针对新版本)
create user ‘user’@‘ip’ identified by ‘123456’;#创建一个主机地址是ip登录密码是123456的user用户
grant all privileges on *.* to 'user'@'ip';#链接上一步,给他所有权限

• 指定授权
create user ‘mysql’@‘%’ identified by ‘123456’;#创建一个主机地址可以时任何地址的登录密码是123456的mysql用户(随时随地,在任何地方的进行登录操作)
grant select,create on myemployees.* to 'mysql'@'%';#设置mysql用户只用myemployees库的查,创建权限

flush privilege;#刷新下数据权限
针对mysql8.0版本以上操作时会报错无法链接;
8.0版本因为密码规则和语法规则的改变,所以要再次设置
在相同情况下依次执行以下语句
alter user ‘mysql’@‘%’ identified by ‘123456’ passwore expire never;#修改加密规则
alter user ‘mysql’@‘%’ identified by ‘123456’ mysql_native_password by '123456';#再次重置密码
flush privilege;#刷新下数据权限


试着用工具链接上去看看吧!
福利

边栏推荐
- Sum the two numbers to find the target value
- 【Lua】常见知识点汇总(包含常见面试考点)
- Metaclass type and using metaclass to implement model class ORM
- KS009基于SSH实现宠物管理系统
- Webui automated learning
- 互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
- Solutions to a series of problems in sqoop job creation
- Lunix reallocates root and home space memory
- Windows环境MySQL8忘记密码文件解决方案
- Database dictionary Navicat automatic generation version
猜你喜欢

Blender体积雾

Basic notes of illusory AI blueprint (10000 words)

14.信号量的代码实现

Database dictionary Navicat automatic generation version

Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?

Webui automated learning

Blender camera surround motion, animation rendering, video synthesis

对话吴纲:我为什么笃信“大国品牌”的崛起?

stm32和电机开发(上位系统)
![[unity3d] nested use layout group to make scroll view with dynamic sub object height](/img/b2/edab4ab48e1401934dcce7218df662.png)
[unity3d] nested use layout group to make scroll view with dynamic sub object height
随机推荐
【Lua】常见知识点汇总(包含常见面试考点)
Leetcode -- the nearest common ancestor of 236 binary tree
webUI自动化学习
【MySQL】连接MySQL时出现异常:Connection must be valid and open
js setTimeout()与面试题
02-taildir source
14. Code implementation of semaphore
Transport Optimization abstraction
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
MYSQL环境配置
02-taildir source
2021-10-02
[unity3d] production progress bar - make image have the functions of filled and sliced at the same time
[Lua] summary of common knowledge points (including common interview sites)
07 data import sqoop
Rapid prototyping
01-spooldir
Allure -- common configuration items
[pit avoidance guide] pit encountered using ugui: the text component cannot indent the first line by two spaces
Webui automated learning