安装方式
- 压缩包安装
- 添加 apt 源安装
选择压缩包安装,apt源在国内好像都连不通
安装过程
下载压缩包
https://mariadb.org/download/?t=mariadb&p=mariadb&r=11.4.0&os=Linux&cpu=x86_64&pkg=tar_gz&i=systemd&m=xtom_hk
https://archive.mariadb.org//mariadb-5.5.68/bintar-linux-systemd-x86_64/mariadb-5.5.68-linux-systemd-x86_64.tar.gz
# 解压文件
tar -xzvf mariadb-5.5.68-linux-systemd-x86_64.tar.gz
# 移动到安装位置
sudo mv mariadb-5.5.68-linux-systemd-x86_64 /usr/local/
# 创建软链接
sudo ln -s /usr/local/mariadb-5.5.68-linux-systemd-x86_64 /usr/local/mysql
# 添加用户组和用户
sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
# 初始化数据库
cd /usr/local/mysql
sudo scripts/mysql_install_db --user=mysql
# 设置权限
sudo chown -R mysql:mysql /usr/local/mysql
# 启动服务
sudo systemctl start mysql
systemctl start mariadb 服务不存在
# 创建MariaDB systemd服务文件:
sudo nano /etc/systemd/system/mariadb.service
# 文件内容
[Unit]
Description=MariaDB Database Server
Documentation=man:mysqld(8)
Documentation=https://mariadb.com/kb/en/mariadb/documentation/
[Service]
Type=simple
ExecStart=/usr/local/mysql/bin/mysqld
User=mysql
Group=mysql
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
KillSignal=SIGTERM
Restart=on-failure
RestartPreventExitStatus=1
RestartSec=10
PrivateTmp=true
# 重新加载systemd配置
sudo systemctl daemon-reload
# 启动MariaDB服务
sudo systemctl start mariadb
# 如果需要,设置MariaDB在系统启动时自动启动
sudo systemctl enable mariadb
mysql命令不存在
# 手动添加mysql二进制文件路径到PATH:
export PATH=$PATH:/usr/local/mysql/bin
# 创建mysql的符号链接:
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
执行mysql命令可能遇到:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
# 安装libncurses5:
sudo apt-get install libncurses5
# 更新动态链接库缓存:
sudo ldconfig
标签:systemd,5.6,sudo,Ubuntu,22.04,usr,mysql,mariadb,local
From: https://www.cnblogs.com/linma/p/17979448