MariaDB 修改用户远程登录

今天修改MariaDB数据库用户的Host时出现错误:

ERROR 1356 (HY000): View 'mysql.user' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

我的步骤如下:

1.登陆

2.use mysql;

3.执行:update user set host='%' where user='root';

因为MariaDB的user表是一个视图,所以执行的语句和Mysql有所不同,只需要执行如下语句即可:

rename user 'root'@'localhost' to 'root'@'%';

另外,附创建用户和给用户赋权的操作:

创建用户:create user '用户名'@'%' identified by '密码';

修改用户密码:alter user '用户名'@'%' identified by '密码';

删除用户:drop mysql.user '用户名'@'%';

授权用户:grant all on . to '用户名'@'%' identified by '密码' with grant option;

修改完权限 后,设置Mariadb允许远程链接
1.修改Mariadb配置文件

将/etc/mysql/mariadb.conf.d/50-server.cnf中bind-address = 127.0.0.1加# 注释掉
2.重启服务

go 复制代码
systemctl restart mariadb.service

3.远程链接

mysql -u root -proot -h 192.168.199.240 -D mysql

go 复制代码
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.1.34-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mysql]> 
相关推荐
TechWJ31 分钟前
没有公网 IP 也想远程连 PostgreSQL?从本地数据库到固定 TCP 地址完整配置
大数据·数据库·网络安全·postgresql·内网穿透
又见情义1 小时前
RK3568 Android 13 屏蔽 healthd 电池日志经验分享
android
得物技术1 小时前
指标平台:从语义底座到智能消费的实践路径|得物技术
数据库·人工智能·ai编程
StarRocks_labs1 小时前
当大模型调用进入执行引擎:StarRocks AI Function 全新能力解析
数据库·starrocks·sql·ai·pipeline·数据处理·join
TDengine (老段)2 小时前
TDengine 常见问题 TOP4
数据库·物联网·时序数据库·tdengine·涛思数据·升级·tdengine 问题
小蒜学长2 小时前
基于RFID技术的仓储管理系统设计(代码+数据库+LW)
java·数据库·spring boot·后端·rfid技术·仓储管理
梦影_2 小时前
Langchain简单快速上手教程(五)——聊天模型之流式传输
java·数据库·人工智能·python·langchain
数据狐(Datafox)2 小时前
1688商品列表API接口解析(附 JSON 样例)
java·开发语言·数据库·爬虫·json
adinnet20263 小时前
客服与工单:响应时长与满意度问数
数据库·人工智能
文人sec3 小时前
MYSQL:insert...select:为什么锁源表的所有行和间隙?怎么最快地复制一张表?
数据库·python·mysql