centos7.9安装mysql8.0

centos7.9安装mysql8.0

如果安装过,需删除之前的版本

# 检测
rpm -qa |grep mysql
# 删除
rpm -e mysql-community-common-5.7.34-1.el7.x86_64
rpm -e mysql-community-server-5.7.34-1.el7.x86_64
rpm -e mysql-community-libs-5.7.34-1.el7.x86_64
rpm -e mysql-community-libs-compat-5.7.34-1.el7.x86_64
rpm -e mysql57-community-release-el7-11.noarch
rpm -e mysql-community-client-5.7.34-1.el7.x86_64

yum 换源

新建 /etc/yum.repos.d/mysql-community.repo,内容在这个网址里

下载

yum install mysql-community-server mysql-community
mysql -V   //查看当前安装mysql版本

配置

mysql会自动创建一串随机密码,所以第一次登陆需要用这串随机密码登录。

$ systemctl start mysqld
$ grep "password" /var/log/mysqld.log #找到root@localhost:后面的密码,copy下来
2024-01-11T15:46:23.733859Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Rhf.qMQOX2(e
$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.35

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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 'Tongji@2020';	//重置mysql密码为:Tongji@2020
Query OK, 0 rows affected (0.01 sec)

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

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
posted @ 2024-01-11 23:57  DarkLights  阅读(13)  评论(0)    收藏  举报