Ubuntu 16.04 部署Mariadb

默认上MariaDB的包并没有在Ubuntu仓库中。要安装MariaDB,我们要设置MariaDB仓库。

sudo apt-get install software-properties-common

sudo apt-keyadv--recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.neusoft.edu.cn/mariadb/repo/10.3/ubuntu xenial main'

2.3 安装MariaDB

sudo apt update 

sudo apt install mariadb-server

在安装中,你会被要求设置MariaDB的root密码。

 
 

三、运行

3.1 通过命令行连接MariaDB

mysql -u root -p

 
 

3.2 MariaDB 服务启动与停止

sudo/etc/init.d/mysql stop

sudo/etc/init.d/mysql start

systemctl start mariadb

systemctl status mariadb

 
 

四、配置

4.1 允许远程访问

如果Ubuntu有设置防火墙或者iptables规则的话,请允许指定端口号访问

判断3306端口是否打开

4.1.1 使用 netstat命令查看3306端口状态

netstat -an | grep 3306

 
 

从上面结果可以看出3306端口只在IP 127.0.0.1 上监听,所以拒绝了其他IP的访问。

解决方案:

修改/etc/mysql/my.cnf文件。找到下面内容:

# Instead of skip-networking thed efault 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,建议注释掉。

重新启动后,重新使用netstat检测。

 
 

使用命令测试

mysql -h192.168.0.xxx -u root -p

Enter password:ERROR1130(HY000): Host'192.168.0.xxx'isnotallowedtoconnecttothis MariaDB server

解决方案:需要将用户权限分配给各个远程用户

登录mysql服务器,使用grant命令分配权限

grant all on *.* to '用户名'@'%' identified by '密码';

例子:grant all on *.* 'root'@'%' identified by '123456';

 
 

这样即可远程访问了。

查看ubutu安装软件时间

/var/log/apt/history.log
/var/log/apt/term.log
/var/log/aptitude

原文地址:https://www.cnblogs.com/daofaziran/p/12335916.html