Centos7中安装mariadb

1.  etc/yum.repos.d下新建Centos-MariaDB.repo添加mariadb的yum源
[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos7-amd64/
gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

2.清除yum缓存并重新建立
yum clean all
yum makecache
  第二步如果报错删除yum.repos.d下的所有文件
   rm -f /etc/yum.repos.d/*
   重新下载阿里的
   wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
   下载后重新执行第二步
   
3.开始安装
yum install MariaDB-client MariaDB-server MariaDB-devel -y

4.启动服务并设为开机启动
systemctl start mariadb
systemctl enable mariadb

5.初始化数据库,并删除测试数据库及更改权限和设置密码
mysql_secure_installation

6.设置远程连接
   6.1允许root使用任何主机连接 
   GRANT ALL PRIVILEGES ON *.*   TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
   6.2刷新权限
   FLUSH PRIVILEGES;
   6.3开放3306端口或关闭防火墙并禁止开机启动
   firewall-cmd --zone=public --add-port=3306/tcp --permanent
   
   systemctl stop firewalld.service #停止firewall
   systemctl disable firewalld.service #禁止firewall开机启动
   
7.设置默认编码为utf-8
  查看看当前默认编码
  SHOW VARIABLES LIKE 'character%'
  vi /etc/my.cnf  添加下面内容
  [mysqld]
  collation-server = utf8_general_ci
  character-set-server = utf8
  
  vi /etc/my.cnf.d/mysql-clients.cnf 在[musql]标签下添加
  default-character-set=utf8

8.重启mariadb服务
  systemctl restart mariadb.service
  
创建用户并授权某个数据库的操作权限
CREATE USER 'username'@'%' IDENTIFIED BY 'password';   #创建用户
update mysql.user set password=password('新密码') where user='username';  # 修改密码
grant all privileges on 数据库名.* to 'username'@'%';     #授权  all可以替换为select,delete,update,create,drop

上面的语句后要刷新权限
flush privileges;
  
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值