centos7.6 安装mariadb10.10

156 阅读2分钟

1.旧版本删除

先查出旧版文件,旧版必须得删除,不然麻烦很多

rpm -qa | grep mariadb

再逐个删除(文件名可能不同,按自己的来)

yum remove mariadb-server-5.5.68-1.el7_5.x86_64
yum remove mariadb-5.5.68-1.el7_5.x86_64
yum remove mariadb-libs-5.5.68-1.el7_5.x86_64

2.创建MariaDB.repo文件

在目录 /etc/yum.repos.d/ 下创建文件 MariaDB.repo

vim /etc/yum.repos.d/MariaDB.repo

将以下代码复制进去(这里用了阿里云镜像,不是国外服务器,原网站无法用)

[mariadb]
 
name = MariaDB
 
baseurl = http://mirrors.aliyun.com/mariadb/yum/10.10/centos7-amd64/
 
gpgkey =  http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
 
gpgcheck = 1

按5次(esc ) + (:wq) + 按下(enter) 保存文档并返回

3.安装mariadb10

sudo yum install -y MariaDB-server MariaDB-client

4.初始化配置

启动MariaDB

systemctl start mariadb

开启自启动

systemctl enable mariadb

查看状态

systemctl status mariadb

5.设置密码

这时候是没密码的,直接进入

mysql -uroot
use mysql;
update user set password=password("123456") and Host="%" where User='root';
FLUSH PRIVILEGES;

下面这个方法经测试报错,没采用

进入密码设置页

mariadb-secure-installation

**10.5.2之前的版本用下面命令

mysql_secure_installation

首次没有密码,直接多次回车,跳过以下提示

Enter current password for root (enter for none):<–初次运行直接回车

设置密码

Enable unix_socket authentication? [Y/n] ->N
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
Y
设置密码时,是不可见的,直接盲打,然后回车就行

New password: 
 
Re-enter new password: 
Remove anonymous users? [Y/n] 
是否删除匿名用户,Y,回车
Disallow root login remotely? [Y/n]
是否禁止root远程登录,N,回车,
Remove test database and access to it? [Y/n]
是否删除test数据库,N,回车
Reload privilege tables now? [Y/n] 
是否重新加载权限表,直接回车

6.测试

-u 后接用户名,这里是root -p 后接密码,这里是123456

mysql -uroot -p123456

7.其他

配置字符集 vi /etc/my.cnf 文件中写入以下

[mysqld]
 
init_connect='SET collation_connection = utf8_general_ci'
 
init_connect='SET NAMES utf8'
 
character-set-server=utf8
 
collation-server=utf8_general_ci
 
skip-character-set-client-handshake

vi /etc/my.cnf.d/client.cnf 文件中写入以下

default-character-set=utf8

vi /etc/my.cnf.d/mysql-clients.cnf 文件中写如以下

default-character-set=utf8

重启

systemctl restart mariadb