当前位置:网站首页>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;#刷新下数据权限
试着用工具链接上去看看吧!
福利
边栏推荐
- Pytest-- test report allure configuration
- Is this code PHP MySQL redundant?
- 4. Random variables
- 【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
- Importing tables from sqoop
- "Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
- 转换YV12到RGB565图像转换,附YUV转RGB测试
- 网络通信学习
- 对话吴纲:我为什么笃信“大国品牌”的崛起?
- Ks009 implement pet management system based on SSH
猜你喜欢
Message mechanism -- getting to know messages and message queues for the first time
2021-10-02
Ks009 implement pet management system based on SSH
Sum the two numbers to find the target value
"Matching" is true love, a new attitude for young people to make friends
Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)
Flutter——Canvas自定义曲线图
Blender volume fog
[SUCTF2018]followme
01 install virtual machine
随机推荐
【Lua】常见知识点汇总(包含常见面试考点)
Zlib download and use
Flink submitter
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Retrofit's callback hell is really vulnerable in kotlin synergy mode!
[SUCTF2018]followme
13. Semaphore critical zone protection
Feature (5): how to organize information
STM32 and motor development (upper system)
allure--常用配置项
使用Windbg静态分析dump文件(实战经验总结)
测试--面试题总结
【leetcode】33. Search rotation sort array
2021-09-12
SAP Spartacus express checkout design
Leetcode -- the nearest common ancestor of 236 binary tree
Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)
Basic notes of illusory AI blueprint (10000 words)
Pytest-- test report allure configuration
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?