在Linux上安装MariaDB(MySQL)数据库(新版)

2022-03-02 00:00:00 用户 代码 密码 权限 复制

前言

近云服务器到期了,正好前几天购买了新的树莓派,准备在家里搭建一个小服务器用于编程测试。在配置 MariaDB 的时候发现和之前的方式有些许变化,现在整理成这篇文章。

安装

这里模拟的是在远程服务器配置 MariaDB,如果你是在本地安装可以对下列步骤自行取舍。

具体步骤如下:

步 通过 SSH 登录远程服务器,具体步骤可以参考在Mac上通过SSH登录远程服务器。

第二步 通过 apt 或者 yum 的方式安装 MariaDB,这里以 apt 为例(用何种方式安装,取决于你的 Linux 系统和你的使用习惯)

sudo apt-get update // 先对系统进行更新,不更新有时会出现错误
sudo apt-get install mariadb-server // 更新完成后,安装 mariadb-server
复制代码

配置

执行下列代码进行相关配置

sudo mysql_secure_installation // 注意要使用管理员权限执行
复制代码

首先提示输入数据库 root 用户密码

  • 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] <– 是否删除匿名用户
  • Disallow root login remotely? [Y/n] <–是否禁止root远程登录
  • Remove test database and access to it? [Y/n] <– 是否删除test数据库
  • Reload privilege tables now? [Y/n] <– 是否重新加载权限表

当然你也可以用下面的方式修改 root 密码:

$ sudo mysql -u root // 直接回车即可,出现下面的文字,即为登录成功

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.37-MariaDB-0+deb9u1 Raspbian 9.0

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
复制代码

然后通过如下步骤修改密码

相关文章