ubuntu14.04 安装MariaDB10.0并允许远程访问

Posted 洽洽老大

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu14.04 安装MariaDB10.0并允许远程访问相关的知识,希望对你有一定的参考价值。

MariaDB是一个社区驱动的、采用XtraDb存储引擎的mysql分支版本,由MySQL创始人Michael Widenius带领开发,遵循GPL v2.0协议开源。因为MySQL创始人的介入,MariaDB备受关注,Drupal、MediaWiki、phpMyAdmin、WordPress等众多应用都宣布支持MariaDB。

安装

MariaDB的包默认没有在Ubuntu仓库中。首先设置MariaDB仓库。

$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
$ sudo add-apt-repository 'deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main'

更新并安装

sudo apt-get update
sudo apt-get install mariadb-server

安装过程中设置一下root密码.
安装完毕后,使用命令行连接MariaDB

qiaqia@qiaqiac:~$ mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \\g.
Your MariaDB connection id is 43
Server version: 10.0.24-MariaDB-1~trusty mariadb.org binary distribution

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

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

MariaDB [(none)]> 

开启MariaDB服务

sudo service mysql start

关闭MariaDB服务

sudo service mysql stop

使MariaDB允许远程访问

  1. 确定服务器上的防火墙没有阻止 3306 端口
  2. 使用nestat命令查看3306端口状态:

    netstat -an | grep 3306

    显示3306端口只监听127.0.0.1, 其他IP无法访问

    qiaqia@qiaqiac:~$ netstat -an | grep 3306
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
    tcp        0      0 127.0.0.1:43825         127.0.0.1:3306          ESTABLISHED
    tcp        0      0 127.0.0.1:3306          127.0.0.1:43826         ESTABLISHED
    tcp        0      0 127.0.0.1:3306          127.0.0.1:43825         ESTABLISHED
    tcp        0      0 127.0.0.1:43826         127.0.0.1:3306          ESTABLISHED

    解决方法:修改/etc/mysql/my.cnf文件。打开文件,找到下面内容:

     # Instead of skip-networking the default is now to listen only on
     # localhost which is more compatible and is not less secure.
     bind-address  = 127.0.0.1

    把上面这一行注释掉或者把127.0.0.1换成合适的IP,建议注释掉。

  3. 重新启动后,重新使用netstat检测:

    netstat -an | grep 3306

    显示:

    qiaqia@qiaqiac:~$ netstat -an | grep 3306
    tcp6  0 0 :::3306     :::*       LISTEN   
  4. 在MariaDB服务器上授权允许远程访问

    首先以root用户登陆MariaDB服务器

    允许用户名为`qiaqia`的用户从任意ip以密码为123456访问所有数据库
    grant all PRIVILEGES on *.* to qiaqia@'%' identified by '123456';

    解释:

    1. all PRIVILEGES 表示赋予所有的权限给指定用户,这里也可以替换为赋予某一具体的权限,例如:select,insert,update,delete,create,drop 等,具体权限间用“,”半角逗号分隔
    2. *.*表示权限是作用于哪个数据库哪个表的,*.*表示所有数据库的所有表,格式为:数据库名.表名*表示所有。
    3. qiaqia 表示你授权的用户名,该用户可存在可不存在
    4. '%'表示所有ip,也可以是特定的ip
    5. '123456'是访问的密码。
    6. 最后> flush privileges;使其生效

以上是关于ubuntu14.04 安装MariaDB10.0并允许远程访问的主要内容,如果未能解决你的问题,请参考以下文章

MariaDB + phpmyadmin 在 ubuntu 14.04 上使用 Nginx

deepin 15.3 安装数据库MariaDB10.0

Ubuntu下安装Nginx

windows server 2003 怎么安装mariadb 10.0

安装MariaDB10.0 在学校的电脑上同样的安装包能装 但是为啥我的电脑就是装不上?是惠普的

CentOS用yum安装配置MariaDB