centOS7安装mysql5.7

1、查看系统是否安装历史版本
# 查看
rpm -qa|grep mysql
rpm -qa|grep mariadb
# 卸载
yum -y remove  #mysql安装包名称
yum -y remove  #mariadb安装包名称
2、下载安装
[root@localhost ~]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
[root@localhost ~]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
[root@localhost ~]# yum install -y mysql mysql-server
[root@localhost ~]# mysql -V   //查看当前安装mysql版本
mysql  Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using  EditLine wrapper
3、修改密码
[root@localhost ~]# systemctl start mysqld   //启动mysql服务
[root@localhost ~]# grep "password" /var/log/mysqld.log  //通过log查看初始密码
2021-08-05T16:17:00.010786Z 1 [Note] A temporary password is generated for root@localhost: i8d?ur_#rr+O    //i8d?ur_#rr+O此为mysql初始密码
[root@localhost ~]# mysql -u root -p  
Enter password:                         //输入初始密码i8d?ur_#rr+O
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by 'Password@123..';   //重置mysql密码为:Password@123..
Query OK, 0 rows affected (0.00 sec)

mysql> update mysql.user set host='%' where host='localhost';  //root用户可使用任意IP登录数据库
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush privileges;   //刷新权限
posted @ 2021-08-05 17:32  姜家少爷  阅读(49)  评论(0)    收藏  举报