数据库教程:Mariadb远程登陆配置及问题解决

前言:  安装过程不再赘述,直接说问题,mysql的远程连接需要解决两个问题:1.允许root用户远程连接。2.允许任意ip远程连接数据库。当然,在测试和解决问题之前,得首先保证你的数据库与远程主机之

前言:

  安装过程不再赘述,直接说问题,mysql的远程连接需要解决两个问题:1.允许root用户远程连接。2.允许任意ip远程连接数据库。当然,在测试和解决问题之前,得首先保证你的数据库与远程主机之间的网络通信没有问题,简单的来说,就是互相ping通,其次,为了避免防火墙的干扰,将本地主机和数据库主机的防火墙都关闭,当然,生产环境下防火墙肯定是要打开的,并且需要额外的安全配置。

问题解决:

1.新安装的数据库默认是需要初始化的,在数据库服务启动的情况下,使用下面的命令来进行初始化。

  [root@localhost ~]# mysql_secure_installation  new password:   re-enter new password:   password updated successfully!  reloading privilege tables..   ... success!      by default, a mariadb installation has an anonymous user, allowing anyone  to log into mariadb without having to have a user account created for  them. this is intended only for testing, and to make the installation  go a bit smoother. you should remove them before moving into a  production environment.    remove anonymous users? [y/n]    ... success!    normally, root should only be allowed to connect from 'localhost'. this  ensures that someone cannot guess at the root password from the network.    disallow root login remotely? [y/n] n  #如果是为root用户配置远程登陆,这里需要选择n,不选择禁止root用户远程登陆,别的选择都无关紧要。   ... skipping.    by default, mariadb comes with a database named 'test' that anyone can  access. this is also intended only for testing, and should be removed  before moving into a production environment.    remove test database and access to it? [y/n]    - dropping test database...   ... success!   - removing privileges on test database...   ... success!    reloading the privilege tables will ensure that all changes made so far  will take effect immediately.    reload privilege tables now? [y/n]    ... success!    cleaning up...    all done! if you've completed all of the above steps, your mariadb  installation should now be secure.    thanks for using mariadb![root@localhost ~]# systemctl restart mariadb  #完成初始化之后,重启服务。

2.允许root用户远程连接与允许任意ip远程连接数据库都是可以通过在数据库里执行一条命令来实现的。

这里分为两种情况:

1)新建admin用户远程连接mysql数据库(新建任意用户,以admin为例)

grant all on *.* to admin@’%’ identified by ‘123456’ with grant option;
flush privileges;

允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。
注意admin账户不一定要存在。

2)支持root用户允许远程连接mysql数据库

grant all privileges on *.* to ‘root’@’%’ identified by ‘123456’ with grant option;
flush privileges;

需要注意的是,为root用户配置远程登陆,密码需要和之前配置的密码一致。

3.ubuntu系统的额外配置。

ubuntu系统的my.cnf文件在vim /etc/mysql/mysql.conf.d/mysqld.cnf中,注释掉其中的

bind-address = 127.0.0.1

centos系统的配置文件中默认没有该行。

检查的办法也很简单,在数据库启动的前提下,使用netstat -an | grep 3306查看端口的连接信息。0.0.0.0则表示允许任意ip连接。

Mariadb远程登陆配置及问题解决

如图所示则为允许任意ip连接。

以上就是数据库技术:Mariadb远程登陆配置及问题解决的全部内容,希望对大家的学习有所帮助,也希望大家多多支持<计算机技术网(www.ctvol.com)!!>。

需要了解更多数据库技术:Mariadb远程登陆配置及问题解决,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/dtteaching/630466.html

(0)
上一篇 2021年5月30日
下一篇 2021年5月30日

精彩推荐