栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Ubuntu下联网安装MariaDB

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Ubuntu下联网安装MariaDB

最开始尝试离线安装,一直报libssl.so.10找不到,所以放弃。开始联网安装。

公司在其他服务器上使用的MariaDB版本为10.4.12,最开始安装的版本为MariaDB10.1系列,但安装后发现该版本不支持with as语句……于是卸载重装,新安装的版本为MariaDB10.4.21,解决问题。
在安装过程中遇到部分问题,做此记录。

Ubuntu版本:Ubuntu 18.04.6 LTS

默认版本安装与10.4版本的差异

默认的Ubuntu存储库包含MariaDB软件包,但版本已过期,Ubuntu 18.04/18.10都只包含MariaDB 10.1。笔者最开始不知道,所以直接安装了,在此简略说明与10.4版本的差异。

安装默认(10.1)版本时,直接运行apt install mariadb-server即可。安装其他版本时需要先去官网下载仓库。

在远程连接时,Navicat一直报错:

Can’t connect to MySQL server on ‘######’ (10061)

,经查询需要将bind-address = 127.0.0.1参数屏蔽掉。

在默认安装的10.1版本中,该参数存放在
/etc/mysql/mariadb.conf.d/50-server.cnf中,而10.4版本,该参数存放在
/etc/mysql/my.cnf中。

其他版本安装步骤(以10.4版本为例) 查看已有mariadb版本

终端执行 sudo dpkg -l | grep maria。可用此检查之前是否已有安装过mariadb。

卸载已有版本

sudo apt-get remove mysql-*


再执行

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

若需保留数据文件,则选择“否”,否则选“是”。
再执行一次dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P。如果出现以下类似的信息:

没有找到对应软件包信息
则说明卸载成功。

安装新版本

在该地址中,可查找对应版本的安装语句:

https://downloads.mariadb.org/mariadb/repositories/#mirror=neusoft


依次执行:

sudo apt-get install software-properties-common
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.ustc.edu.cn/mariadb/repo/10.4/ubuntu bionic main'

下载完毕后,更新仓库:

sudo apt update

开始下载:

sudo apt install mariadb-server
配置MariaDB

开启服务

systemctl start mariadb  

设置为开机自启动服务

systemctl enable mariadb  

进行首次配置:

mysql_secure_installation


配置字符集(这里使用UTF8MB4)及相关配置,修改/etc/my.cnf文件:
在[mysqld]下添加:

[mysqld]
init_connect=‘SET collation_connection = utf8mb4_general_ci’
init_connect=‘SET NAMES utf8mb4’
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
skip-character-set-client-handshake
default-storage-engine=Innodb #默认引擎为Innodb
innodb_buffer_pool_size=3G
max_length_for_sort_data = 8M
sort_buffer_size =32M
read_rnd_buffer_size = 8M
tmp_table_size=128M
join_buffer_size = 16M
interactive_timeout=9072000
wait_timeout=9072000
innodb_lock_wait_timeout=1800
innodb_file_per_table=1 #防止索引最长限制报错
innodb_file_format=Barracuda #防止索引最长限制报错
innodb_large_prefix = O #防止索引最长限制报错
innodb_strict_mode = 0 #防止索引最长限制报错
max_connections=3000 #最大连接数
event_scheduler=ON #定时任务
lower_case_table_names=1

可根据自己需求修改。
修改/etc/my.cnf.d/mysql-clients.cnf文件
在[mysqld]下添加:

default-character-set=utf8

重启MariaDB
systemctl restart mariadb
远程连接

1、关闭防火墙:

ufw stop

2、使用mysql -uroot -p,连接mariadb,执行如下语句:
①授权
(注:identified by 后为登录密码)

grant all privileges on *.* to 'root'@'%' identified by '******' with grant option;

②刷新权限

flush privileges;

使用客户端远程连接,如果连接不上,报错Can’t connect to MySQL server on ‘######’ (10061),则修改/etc/mysql/my.cnf文件,将bind-address = 127.0.0.1屏蔽掉。

#bind-address = 127.0.0.1

再次重启服务

systemctl restart mariadb

引用:

https://www.jianshu.com/p/abb84a405657
https://blog.csdn.net/bigsea622/article/details/105807739/
https://www.cnblogs.com/helloHT/p/11849603.html

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/341556.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号