• Linux安装Mariadb数据库


    第一步,执行安装命令:

    yum install mariadb-server
    
    • 1

    由于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
    
    • 1
    • 2

    然后执行

    yum clean all
    
    • 1

    报错
    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
    
    • 1

    看到一些其他教程只修改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
    
    • 1

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

    3.清理、生成缓存

    yum clean all
    yum makecache
    
    • 1
    • 2

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

    在线安装成功后

    启动命令      systemctl  start  mariadb
    重启命令      systemctl restart  mariadb
    关闭命令      systemctl stop  mariadb
    设定开机自起   systemctl  enable mariadb 
    关闭开机自起   systemctl  disable mariadb 
    
    • 1
    • 2
    • 3
    • 4
    • 5

    执行: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
    
    • 1

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

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

    mysql_secure_installation
    
    • 1

    设置完密码 一 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或者回车。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    登陆mariadb数据库

    mysql -u root -p
    
    • 1

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

    创建用户和赋操作权限

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

    mysql -u root -p 'root_password' 
    
    • 1

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

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

    3 .配置权限

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

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

     create database mynewdatabase;
    
    • 1

    ALL: 所有可用的权限

    CREATE: 创建库、表和索引

    LOCK_TABLES: 锁定表

    ALTER: 修改表

    DELETE: 删除表

    INSERT: 插入表或列

    SELECT: 检索表或列的数据

    CREATE_VIEW: 创建视图

    SHOW_DATABASES: 列出数据库

    DROP: 删除库、表和视图

    完全卸载mariadb

    1、卸载mariadb:

    yum remove mariadb
    
    • 1

    2、删除配置文件:

    rm -f /etc/my.cnf
    
    • 1

    3、删除数据目录:

    rm -rf /var/lib/mysql/
    
    • 1

    修改Mariadb数据库端口

    Linux下

    vim /etc/my.cnf
    
    • 1

    在 Debian/Ubuntu 下

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

    修改内容

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

    重启Mariadb后检验一下

    mysql  -u root -p -P 端口号
    show variables like 'port';
    
    • 1
    • 2
  • 相关阅读:
    EXCEL day 02 公式和函数
    【MATLAB的方程组求解】
    区域气象-大气化学在线耦合模式(WRF/Chem)在大气环境领域实践技术应用
    【毕业设计】深度学习 YOLO 实现车牌识别算法
    Python测试-unittest,2022-11-27
    Vovsoft Text Edit Plus 专业文本编辑器工具软件:简洁高效的创作利器
    3.3 【MySQL】字符集和比较规则的应用
    Spark SQL 的总体工作流程
    【算法】排序——插入排序及希尔排序
    【.net core】解决无法下载wgt文件问题
  • 原文地址:https://blog.csdn.net/weixin_44629395/article/details/126462998