MySQL MariaDB配置密码以及远程访问

环境
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 '[email protected]' (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


猜你喜欢

转载自blog.51cto.com/fengyuzaitu/2463026
今日推荐