CentOS7 安装 MySql (MariaDB10.2)

文章介绍了在CentOS7系统中如何卸载原有的MySQL,然后通过yum仓库安装MariaDB,包括创建repo文件、更新缓存、安装服务、启动服务、设置开机启动、初始化数据库、设置root密码、允许远程访问等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.先卸载系统原来的mysql
2.按照步骤安装https://blog.csdn.net/ling1998/article/details/124070790
1)创建镜像repo文件

[root@localhost src]# vi /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

2)更新yum缓存数据

[root@localhost src]# yum clean all
[root@localhost src]# yum makecache all

(3)安装 & 启动 & 设置开机启动

[root@localhost src]# yum install MariaDB-server MariaDB-client -y
[root@localhost src]# systemctl start mariadb.service
[root@localhost src]# systemctl enable mariadb.service

(4)初始化

[root@localhost src]# mysql_secure_installation
 
Enter current password for root (enter for none):  #初次运行,直接回车 
Set root password? [Y/n] Y    #是否设置root用户密码,输入Y并回车或直接回车
New password:                 #设置root用户密码
Re-enter new password:        #密码确认
Remove anonymous users? [Y/n] #是否删除匿名用户,回车
Disallow root login remotely? [Y/n] n    #是否禁止root远程登录,输入n回车(我需要远程连接)
Remove test database and access to it? [Y/n]     #是否删除test数据库,回车
Reload privilege tables now? [Y/n]     #是否重新加载权限表,回车
Thanks for using MariaDB!

(5)连接数据库

[root@localhost src]# mysql -uroot -p -h localhost -P 3306
Enter password: 
MariaDB [(none)]> 

3.设置可以远程访问
在这里插入图片描述

   1)登录数据库 use mysql;
   2)select Host, User,Password from user;
   3)update user set Host='%' where User='root';

在这里插入图片描述

   4)flush privileges;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值