远程连接MariaDB数据库
1. 连接数据库
2. 授权并刷新权限
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
flush privileges;
3. 查看用户数据
use mysql
select user, password, host from user;
4.修改配置文件,注释bind-address
配置文件地址:/etc/mysql/mariadb.conf.d/50-server.cnf
mysql 数据库的配置文件:/etc/mysql/mysql.conf.d/mysqld.cnf
5.重启数据库
sudo systemctl restart mysql
另外一种方法:适用于mysql
mysql> use mysql Database changed mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | debian-sys-maint | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 5 rows in set (0.00 sec)
更改“mysql” 数据库里的 “user” 表里的 “host” 项,从“localhost”改称“%“
update user set host="%" where user = "root";
mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | root | % | | debian-sys-maint | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | +------------------+-----------+ 5 rows in set (0.00 sec)
flush privileges;