前言
mariadb 和mysql就像亲兄弟的关系,各种语法、驱动啥的,在mysql上能上的,在mariadb上基本都可以直接使用。更多的细节在此不多说。
1、删除旧版本
centos7下默认安装有mariadb数据库,但是是旧版本,在安装新版本前需要先把旧版本删除,有些系统还默认安装mysql,也必须删除,否则与mariadb会产生冲突,如下命令过程:
rpm -qa | grep mariadb
结果如下:
 
 
用命令yum删除以上三个:
yum remove mariadb-server-5.5.60-1.el7_5.x86_64 yum remove mariadb-5.5.60-1.el7_5.x86_64 yum remove mariadb-libs-5.5.60-1.el7_5.x86_64
2,创建 MariaDB.repo
安装最新版本:https://downloads.mariadb.org/mariadb/repositories/#mirror=shanghai-university&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.3
在目录下 /etc/yum.repos.d/ 创建文件: MariaDB.repo
并把以下内容添加到所建文件中
# MariaDB 10.3 CentOS repository list - created 2018-10-16 15:18 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
以上是官方源,这里我们用阿里源,内容如下:
[mariadb] name = MariaDB baseurl = http://mirrors.aliyun.com/mariadb/yum/10.3/centos7-amd64/ gpgkey =  http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1
3、安装 install MariaDB
sudo yum install MariaDB-server MariaDB-client
 
4、 安装完成MariaDB,首先启动MariaDB
systemctl start mariadb
5、 设置开机启动
systemctl enable mariadb
systemctl 常用命令:
systemctl start mariadb #启动服务
systemctl enable mariadb #设置开机启动
systemctl restart mariadb #重新启动
systemctl stop mariadb.service #停止MariaDB
 
6、 接下来进行MariaDB的相关简单配置
输入以下命令:
mysql_secure_installation
先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
设置密码
 
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,Y,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,N,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,n,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
初始化MariaDB完成,接下来测试登录
 
这里我设置的密码:luxxxxxx
7.测试登录
mysql -u root -p
 
成功登录后显示如下:
 
 
8、配置mariaDB相关字符集
1)、文件/etc/my.cnf
vi /etc/my.cnf
添加如下内容:
[mysqld] init_connect='SET collation_connection = utf8_general_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_general_ci skip-character-set-client-handshake
 
2)、文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
在[client]中添加
default-character-set=utf8
 
3)、文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
 
4)、全部配置完成,重启mariadb
systemctl restart mariadb
 
5)、之后进入MariaDB查看字符集
mysql> show variables like "%character%";show variables like "%collation%";
 
 
 
9、添加用户、设置权限
创建用户命令
mysql>create user lhy@192.168.1.10 identified by 'luxxxxxx';
或 直接创建用户并授权的命令
mysql>
grant all on *.* to lhy@192.168.1.10 indentified by 'luxxxxxx';
或 授予外网登陆权限
mysql>grant all privileges on *.* to username@'%' identified by 'password';
或  授予权限并且可以授权
mysql>grant all privileges on *.* to lhy@'192.168.1.10' identified by 'lu5896848' with grant option; mysql>flush privileges;
简单的用户和权限配置基本就这样了。
其中只授予部分权限把 其中 all privileges或者all改为select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。
 10、远程访问数据库
远程访问MySQL,需开放默认端口号3306,方式有两种:
1)、centos6或更早前的版本系统
vi /etc/sysconfig/iptables
修改
 
*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
#在里面加入这2行:
 
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT
#改为
*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT -A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
 
如果该 iptables 配置文件 不存在,先执行yum install iptables-services安装
执行 iptables 重启生效
service iptables restart
2)、centos7
 
执行
firewall-cmd --permanent --zone=public --add-port=3306/tcp firewall-cmd --permanent --zone=public --add-port=3306/udp
这样就开放了相应的端口。
执行
firewall-cmd --reload
 
最后,如果你是用的国外服务器,记得还要设置一个时区 default-time-zone = '+8:00'
另外,如果外部访问不了,尝试把防火墙关闭看一下。

centos7.5下yum 安装mariadb数据库的更多相关文章

  1. centos6下yum安装mariadb数据库的解决方法

    在centos6下Yum安装mariadb数据库时老是提示无法正常安装,看错误日志才发现,是没有mariadb release源文件在/etc/yum.repos.d/中,为此,我特意在新建文件: # ...

  2. centos7下yum安装mariadb

    1.安装MariaDB 删除已安装的mysqlyum remove mysql mysql-server mysql-libs mysql-devel删除存放数据的目录rm -rf /var/lib/ ...

  3. Zabbix之CentOS7.3下yum安装Zabbix3.5

    Zabbix特点介绍 (此介绍来源于https://www.zabbix.com/documentation/3.4/zh/manual/introduction/features) 概述Zabbix ...

  4. CentOS7.3下yum安装MariaDB10.3.12并指定utf8字符集

    添加MariaDB的yum源,指定安装的版本,然后使用 yum 工具进行安装 参考MariaDB官方网站对应安装方法和步骤 https://downloads.mariadb.org/mariadb/ ...

  5. Linux下yum安装MysqL数据库

    1.命令安装mysql # yum install mysql mysql-server mysql-devel -y 最后提示 Complete!  表示安装成功 2.查看是否生成了mysqld服务 ...

  6. centos7.5下yum安装php-5.6.40(LNMP环境)

    cd /etc/yum.repos.d/ yum -y install epel-release #<===安装centos7下php5.6的epel和remi源 rpm -ivh http:/ ...

  7. CentOS7 linux下yum安装redis以及使用

    1.安装redis数据库 yum install redis 2.下载fedora的epel仓库 yum install epel-release 3.启动redis服务 systemctl star ...

  8. 小记centos7.5下yum安装cobbler遇到的问题

    问题1:执行cobbler sync同步命令报错,提示dhcpd服务错误和Python源码错误 [root@server ~]# cobbler sync #<===执行cobbler同步的时候 ...

  9. centos7.5下yum安装mysql-5.6.43

    cd ~/ && cat /etc/redhat-release yum list installed |grep mysql #<===查看是否安装mysql,如果已经安装,使 ...

随机推荐

  1. MySQL密码强度验证修改

    MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格. 影响的语句和函数有:create user,grant,set password,pas ...

  2. jQuery对象的属性操作

    jquery的属性操作模块分为四个部分:html属性操作,dom属性操作,类样式操作和值操作 html属性操作:是对html文档中的属性进行读取,设置和移除操作.比如attr().removeAttr ...

  3. C#分解质因数

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace app ...

  4. Java-左移右移-jdk8

    移位有三种 << 左移,左边补0 >> 右移,正数左边补0,负数补1 >>> 右移, 正数,负数统一左边补0 来看几个奇葩的代码 public static ...

  5. Mysql 多字段去重

    使用group by去重现在有如下表 id name age1 张三 232 李四 343 张三 234 李四 32 需求 : 按照name和age字段联合去重 sql如下 select * from ...

  6. Maven项目指定JDK版本

    <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> ...

  7. Hessian 源码简单分析

    Hessian 是一个rpc框架, 我们需要先写一个服务端, 然后在客户端远程的调用它即可. 服务端: 服务端通常和spring 做集成. 首先写一个接口: public interface Hell ...

  8. redistemplate优雅地操作redis redis 工具类

    参考:https://www.cnblogs.com/superfj/p/9232482.html redis 工具类 package com.service; import org.springfr ...

  9. leetcode1020

    class Solution(object): def __init__(self): self.cons = 0 self.S = list() def dfs(self,m,n,v,A): whi ...

  10. 【转】Intro to ShockBurst/Enhanced ShockBurst

    原地址https://devzone.nordicsemi.com/b/blog/posts/intro-to-shockburstenhanced-shockburst Wireless PC ac ...