当前位置:网站首页>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;#刷新下数据权限


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

边栏推荐
- AI技术产业热点分析
- webUI自动化学习
- 2021-10-02
- 使用sqlcipher打开加密的sqlite方法
- 【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
- Pytest framework implements pre post
- allure--常用配置项
- 2.hacking-lab脚本关[详细writeup]
- [visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
- Blender volume fog
猜你喜欢

Network real-time video streaming based on OpenCV

Postman--使用

axis设备的rtsp setup头中的url不能带参

SUS系统可用性量表

简洁、快速、节约内存的Excel处理工具EasyExcel

12. Process synchronization and semaphore

Feature (5): how to organize information

shell编程01_Shell基础

Stm32 et développement de moteurs (système supérieur)

Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
随机推荐
2021-09-12
Excuse me, is it cost-effective to insure love life patron saint 2.0 increased lifelong life insurance? What are the advantages of this product?
4.随机变量
12.进程同步与信号量
Windows环境MySQL8忘记密码文件解决方案
MYSQL环境配置
13.信号量临界区保护
pytest学习--base
[pit avoidance guide] pit encountered by unity3d project when accessing Tencent bugly tool
[unity3d] production progress bar - make image have the functions of filled and sliced at the same time
Shutter - canvas custom graph
两数之和,求目标值
stm32和電機開發(上比特系統)
flume 190 INSTALL
Ks009 implement pet management system based on SSH
How to get the password of cpolar?
KS009基于SSH实现宠物管理系统
js promise.all
测试--面试题总结
[SUCTF2018]followme