MySQL MariaDB密码以及远程访问权限配置
  TEZNKK3IfmPf 2023年11月13日 20 0

环境
MySQL 版本 Server version: 5.5.64-MariaDB MariaDB Server
Linux版本  CentOS Linux release 7.6.1810 (AltArch)


操作
1)root默认情况下无须密码登陆,直接回车,要求输入密码,直接回车
root@host-172-16-61-102 bin]# mysql -uroot -p
PASSWORD:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.64-MariaDB MariaDB Server

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

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

 

2)选择数据库,否则执行指令出错No database selected
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

 

3)指定root用户的密码是root
MariaDB [mysql]> update user set password=password("root")where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5  Changed: 0  Warnings: 0
注意:
执行无效情况下,可能是版本的问题,查看是否是password字段还是authentication_string字段保存密码
update user set password = password("root"),authentication_string=password("root") where user='root';
通过指令desc user 可以查看当前user的表结构


4)授予访问权限
root用户使用密码从任何主机连接到mysql服务器
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
其中BY后面是root用户的密码:root

只允许192.168.10.168通过root用户连接到mysql服务器
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.10.168' IDENTIFIED BY 'root' WITH GRANT OPTION;

 

5)刷新权限
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)


注意:
1)Navicat远程登陆失败
1045 - Access denied for user 'root@192.168.63.184' (using password: YES)
授予访问权限没有执行,执行第四步
可通过指令 select host,user from user;查看是否有远程访问的权限
2)关闭防火墙
systemctl stop firewalld.service            #停止firewall
systemctl disable firewalld.service        #禁止firewall开机启动
开启端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
mysql服务启动,可以通过lsof -i:3306端口是否监听
重启防火墙
firewall-cmd --reload

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2024年05月31日   24   0   0 mysql
  TEZNKK3IfmPf   2024年05月17日   48   0   0 sqlmysql
  TEZNKK3IfmPf   2024年05月31日   29   0   0 数据库mysql
  TEZNKK3IfmPf   2024年05月17日   48   0   0 查询mysql索引
  TEZNKK3IfmPf   2024年05月17日   50   0   0 jsonmysql
  TEZNKK3IfmPf   2024年05月17日   48   0   0 mysqlphp
  TEZNKK3IfmPf   2024年05月31日   25   0   0 数据库mysql
TEZNKK3IfmPf