linux 安装mysql 8.0(yum方式)
先卸载MariaDB
# 检查有没有 mariadb
rpm -qa | grep -i mariadb
# 卸载mariadb
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
检查是否有mysql残留
# 检查mysql是否有残留
rpm -qa | grep mysql
# 有的话也卸载
rpm -e --nodeps xxxxx
下载mysql库
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
安装mysql库
yum -y install mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-libs-compat -y
重新获取mysql的GPG
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
安装mysql
yum -y install mysql-community-server
开启mysql服务
systemctl start mysqld
- 检查mysql运行状态
systemctl status mysqld
查看默认密码
cat /var/log/mysqld.log | grep password
修改密码&开启远程访问
[root@ybchen-1 mysql]#
[root@ybchen-1 mysql]# pwd
/var/lib/mysql
[root@ybchen-1 mysql]#
[root@ybchen-1 mysql]# cat /var/log/mysqld.log | grep password
2023-05-26T09:41:05.264719Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PNkUvy2E.Pd.
[root@ybchen-1 mysql]#
[root@ybchen-1 mysql]#
[root@ybchen-1 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.33
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 'Root1234.';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> update user set host = '%' where user = 'root';
ERROR 1046 (3D000): No database selected
mysql> update mysql.user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
注意:修改好mysql远程访问后,需要重新刷新权限:flush privileges;