Mysql安装

mysql安装

换阿里镜像源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

wget -O/etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum clean all
yum makecache
yum update

检查

检查是否有之前安装的软件包
rpm -qa|grep mysql
rpm -qa|grep mariadb
如果有,卸载
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps

查找mysql的数据
find / -name mysql
如果有,删除
rm -rf /usr/bin/mysql

开始安装

下载rpm包
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
安装
yum install mysql-community-server

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bZ0dQuBs-1689818281683)(C:\Users\86186\AppData\Roaming\Typora\typora-user-images\image-20230718105256910.png)]

解决方法,执行这条命令

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
重新安装
yum install mysql-community-server

启动

systemctl status mysqld
systemctl start mysqld
systemctl enable mysqld

登录

获取临时密码
grep "temporary password" /var/log/mysqld.log
登录mysql
mysql -uroot -pGr5sRrPA97*T
修改密码
alter user 'root'@'localhost' identified by 'Zhangsb01@';


登录时会报错

报错信息

mysql: [Warning] Using a password on the command line interface can be insecure
vim  /etc/my.cnf
[client]
user=root
password=Zhangsb01@

chmod 600 /etc/my.cnf

在你的主目录下创建一个名为.my.cnf的文件,文件内容如下:

[client]   
user=username   
password=password    

然后修改这个文件的权限,使得只有你可以读取和写入:

  chmod 600 .my.cnf

这样你就可以直接使用mysql命令来登录,而不需要再输入密码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值