Linux安装Mariadb数据库

第一步,执行安装命令:

yum install mariadb-server

由于Linux镜像不可用导致在线下载失败;
直接报错

Failed to set locale, defaulting to C.UTF-8 Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration Repository PowerTools is listed more than once in the configuration Repository centosplus is listed more than once in the configuration
CentOS-8 - AppStream 1.3 kB/s | 394 B 00:00
Errors during downloading metadata for repository 'AppStream':- Status code: 404 for https://repo.huaweicloud.com/centos/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 59.39.0.151)
Error: Failed to download metadata for repo 'AppStream': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

首先解决:Failed to set locale, defaulting to C.UTF-8 问题
执行

echo "export LC_ALL=en_US.UTF8" >> /etc/profile
source /etc/profile

然后执行

yum clean all

报错
Repository AppStream is listed more than once in the configuration Repository extras is listed more than once in the configuration Repository PowerTools is listed more than once in the configuration Repository centosplus is listed more than once in the configuration

解决方法:
1.备份
首先备份原有的repo文件

cd /etc/yum.repos.d && mkdir bak  && mv *.repo ./bak

看到一些其他教程只修改CentOS-Base.repo这个文件,会出现以下提示

image-20220304221624716

2.换阿里云源
有些教程给出的换源网址已经不能再使用,建议查看官网

https://developer.aliyun.com/mirror/centos.

2022年10月如下方式有效

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

本来是想下载java jdk 11,换腾讯云后查看发现没有11的版本,所以使用的阿里云。

3.清理、生成缓存

yum clean all
yum makecache

到此解决镜像问题,继续执行:yum install mariadb-server
在这里插入图片描述
在这里插入图片描述

在线安装成功后

启动命令      systemctl  start  mariadb
重启命令      systemctl restart  mariadb
关闭命令      systemctl stop  mariadb
设定开机自起   systemctl  enable mariadb 
关闭开机自起   systemctl  disable mariadb 

执行:systemctl start mariadb时报错
Job for mariadb.service failed because the control process exited with error code. See “systemctl status mariadb.service” and “journalctl -xe” for details.

这里需要找到安装mariadb的路径:whereis mariadb
我的是在/usr/share/mariadb

cp /usr/share/mariadb/wsrep.cnf  /etc/my.cnf

将.cnf文件复制到/etc文件夹下;

启动systemctl start mariadb
查看状态:systemctl status mariadb.service
在这里插入图片描述
初始化数据库:
在这里插入图片描述

mysql_secure_installation

设置完密码 一 y 到底
按照这个执行就行

Enter current password for root (enter for none): 

让我们输入root用户密码,初次运行直接回车。

Set root password? [Y/n]

是否设置root用户密码,输入y并回车或直接回车。

New password: 
Re-enter new password: 

输入新密码,并确认密码。

其他配置

Remove anonymous users? [Y/n]        是否删除匿名用户,输入y或者回车。

Disallow root login remotely? [Y/n]        是否禁止root远程登录,输入y或者回车。

Remove test database and access to it? [Y/n]        是否删除test数据库,输入y或者回车。

Reload privilege tables now? [Y/n]         是否重新加载权限表,输入y或者回车。

登陆mariadb数据库

mysql -u root -p

输入刚刚设置的密码
在这里插入图片描述

创建用户和赋操作权限

1 .使用具有数据库管理权限的用户登陆MySQL,如root@localehost用户

mysql -u root -p 'root_password' 

2 .在mysql中创建用户名和密码

create user 'new_username'@'%' IDENTIFIED BY 'new_password';

3 .配置权限

grant all privileges on *.* TO 'new_username'@'%' with grant option;

4 .创建数据库( //注意别漏了“;”分号哦)

 create database mynewdatabase;

ALL: 所有可用的权限

CREATE: 创建库、表和索引

LOCK_TABLES: 锁定表

ALTER: 修改表

DELETE: 删除表

INSERT: 插入表或列

SELECT: 检索表或列的数据

CREATE_VIEW: 创建视图

SHOW_DATABASES: 列出数据库

DROP: 删除库、表和视图

完全卸载mariadb

1、卸载mariadb:

yum remove mariadb

2、删除配置文件:

rm -f /etc/my.cnf

3、删除数据目录:

rm -rf /var/lib/mysql/

修改Mariadb数据库端口

Linux下

vim /etc/my.cnf

在 Debian/Ubuntu 下

vim /etc/mysql/mariadb.conf.d/50-server.cnf 

修改内容

[mysqld]下加入一行 或者修改
port = 12345

重启Mariadb后检验一下

mysql  -u root -p -P 端口号
show variables like 'port';
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值