设置 MariaDB 仓库
默认MariaDB的包并没有在Ubuntu仓库中。要安装MariaDB,我们首先要设置MariaDB仓库。(ubuntu server 版跳过这一步)
1. sudoapt−getinstallsoftware−properties−common2. sudo apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
3. $ sudo add-apt-repository ‘deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main’
安装 MariaDB
- $ sudo apt-get update
- $ sudo apt-get install mariadb-server
从命令行连接到MariaDB
- fengdu@localhost:~$ mysql -u root -p
- Enter password:
从命令行连接到MariaDB
- 如果Ubuntu有设置防火墙或者iptables规则的话,请自行打开
- 3306端口是不是没有打开?
使用nestat命令查看3306端口状态:
~# netstat -an | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
从结果可以看出3306端口只是在IP 127.0.0.1上监听,所以拒绝了其他IP的访问。
解决方法:
nano /etc/mysql/my.cnf 打开文件,添加 bind-address = * 到文件中
运行 service mysql stop
运行 service mysql start
分配用户权限
- 登录到mariadb服务器,使用grant命令分配权限
mariadb> grant all on . to ‘root’@’%’ identified by ‘你的密码’;
root 是你的用户名
% 代表所有的远程ip