Debain和MariaDB简单设置

1. Debian静态ip设置

没有网络寸步难行,所以要首先设置静态IP访问,确保网络正常。

  1. 设置静态IP
bash 复制代码
vi /etc/network/interfaces

auto ens33                # 开机自启ens33网卡
iface lo inet loopback    # 设置回环网卡
allow-hotplug ens33      
iface ens33 inet static   # 设置静态
address 192.168.17.102    
netmask 255.255.255.0
gateway 192.168.17.254

vi /etc/resolv.conf

nameserver 192.168.17.254
nameserver 114.114.114.114
nameserver 8.8.8.8

systemctl restart networking  # 重启网络

ping www.baidu.com # 测试网络是否联通,如果通了就可以远程连接了

注意:

在debian默认的终端中,如果语言设置为中文,那么会出现菱形乱码,但是通过Xshell远程访问就能避免这个问题,暂不解决乱码问题。

2. 安装VIM

bash 复制代码
apt update
apt install vim # 用于修改配置文件,要首先安装

3. 更改环境变量

/usr/sbin文件夹中有许多方便的指令,例如serviceifconfig等。

bash 复制代码
vim /etc/profile

export PATH=$PATH:/usr/sbin #文末追加,保存退出

source /etc/profile

4. MariaDB安装

MariaDB是Mysql的一个分支,完全兼容Mysql指令。

mariadb安装指令:

bash 复制代码
apt install mariadb-server

安装后的MariaDB配置文件在/etc/mysql文件夹下。

5. 数据服务启动

bash 复制代码
# 以下三条指令作用相同
systectl start mariadb
service mariadb start
serivce mysql start

6. 数据库登录

默认情况下,MariaDB数据库密码为空,直接mysql就能进入:

bash 复制代码
root@debian:/home/wei# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 10.5.19-MariaDB-0+deb11u2 Debian 11

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)]> 

注意:

有些情况下,新安装的MariaDB默认密码并不为空,如果数据库中并无重要数据,建议卸载重装。

原因是,经过多个版本的迭代,Mysql已经堵上了很多逻辑上的漏洞,导致密码更改非常困难。

7. 更改Root密码

sql 复制代码
use mysql;
alter user root@localhost identified by '123456'; # 将密码设为123456
exit; # 退出系统
mysql -uroot -p # 使用密码登录

8. 设置MariaDB远程访问

将所有数据库权限均赋予从远程访问的root用户。

  1. 更改bind-address值为0.0.0.0
bash 复制代码
vim /etc/mysql/mariadb.conf.d/50-server.cnf # 配置文件

# bind-address = 127.0.0.1 
bind-address = 0.0.0.0 

注意

有网络教程认为,注释掉bind-address即可,本人亲测无效

所以,务必将bind-address的值修改为0.0.0.0

  1. 赋予远程访问权限
sql 复制代码
# 登录后执行
grant all privileges on *.* to root@'%' identified by '123456' with grant option;
flush privileges;

9. 解决菱形乱码问题

在Debian安装的过程中,如果选择了中文作为系统默认语言,那么就会出现菱形乱码问题。

使用Xshell远程访问可以规避这个问题,在Xshell软件中正常显示中文,没必要解决这个问题。

但是,如果有个人需求,可以把默认的语言改为英文,如下:

bash 复制代码
dpkg-reconfigure locales # dpkg指令存在与/usr/sbin文件夹中

使用上下键和空格选择语言:

  1. 选择en_US.UTF-8
  2. 取消选择zh_CN.UTF-8
  3. 重启

以上为全部内容。

相关推荐
lsz1525907 分钟前
Citrix虚拟化实战:数据库虚拟机扩容流程图文简解
数据库·数据库扩容·citrix虚拟化·平台数据库扩容·虚拟机快照
云浪44 分钟前
从 0 到实战:掌握向量数据库 Milvus,构建 AI 应用的核心能力
javascript·数据库·人工智能
tachibana21 小时前
知识库文档上传接口
数据库·人工智能·大模型·llm
可乐ea1 小时前
Tool Calling 工具调用:让 Agent 查询数据库、调用接口和执行任务
数据库·prompt·agent·tool
Yan_chen6661 小时前
CTFHub SQL 布尔盲注实战攻略
数据库·sql·实战·布尔盲注·ctfhub闯关
杨_晨2 小时前
LLM输出康熙部首冲突
数据库·python·mysql·ai
爱看报的猿2 小时前
【金仓数据库征文】MySQL至金仓KES异构数据库平滑迁移与性能深度调优实战
数据库·数据仓库·mysql·金仓数据库征文
程序猿的学习2 小时前
同一个 Key 写入两次,StarRocks 会留下什么?四种表模型讲明白了
数据库
朱峥嵘(朱髯)2 小时前
数据库如何根据全表 NDV 估算子集的 NDV
数据库·算法
Nturmoils3 小时前
MongoDB迁移:从烟囱式部署走向 KES-AI 时代融合数据库架构
数据库