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


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

边栏推荐
- 01-spooldir
- Aiphacode is not a substitute for programmers, but a tool for developers
- Retrofit's callback hell is really vulnerable in kotlin synergy mode!
- Blender体积雾
- 12.进程同步与信号量
- Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
- flume 190 INSTALL
- [visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
- js setTimeout()与面试题
- Blender model import UE, collision settings
猜你喜欢

Basic usage of mock server

【避坑指南】使用UGUI遇到的坑:Text组件无法首行缩进两格

How to get the password of cpolar?

JS reduce accumulator

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

VLAN experiment

Allure -- common configuration items

Sus system availability scale

STM32 and motor development (upper system)

MongoDB-快速上手MongoDB命令行的一些简单操作
随机推荐
[pit avoidance guide] pit encountered by unity3d project when accessing Tencent bugly tool
SQOOP 1.4.6 INSTALL
Postman--使用
SAP Spartacus express checkout design
Allure -- common configuration items
Database dictionary Navicat automatic generation version
Rapid prototyping
MYSQL环境配置
This article takes you to learn in detail what is fiber to home FTTH
flume 190 INSTALL
转换YV12到RGB565图像转换,附YUV转RGB测试
Operator-1初识Operator
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
07数据导入Sqoop
合并有序数列
Blender camera surround motion, animation rendering, video synthesis
stm32和電機開發(上比特系統)
Blender stone carving
大华设备播放过程中设置播放速度
pytest--之测试报告allure配置