1、先检查系统是否装有mysql
rpm -qa|grep msyql
2、下载mysql的repo源
wget http://repo.mysql.com/mysql57-community-release-el7.rpm
rpm -ivh mysql57-community-release-el7.rpm
--2020-09-16 10:18:00-- http://repo.mysql.com/mysql57-community-release-el7.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.211.97.88
Connecting to repo.mysql.com (repo.mysql.com)|23.211.97.88|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25680 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7.rpm’
100%[===================================================>] 25,680 --.-K/s in 0.07s
2020-09-16 10:18:00 (343 KB/s) - ‘mysql57-community-release-el7.rpm’ saved [25680/25680]
[root@ src]# rpm -ivh mysql57-community-release-el7.rpm
warning: mysql57-community-release-el7.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-11 ################################# [100%]
3、安装mysql
yum install mysql-server
...
Installed:
mysql-community-libs.x86_64 0:5.7.31-1.el7
mysql-community-libs-compat.x86_64 0:5.7.31-1.el7
mysql-community-server.x86_64 0:5.7.31-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:5.7.31-1.el7
mysql-community-common.x86_64 0:5.7.31-1.el7
Replaced:
mariadb-libs.x86_64 1:5.5.65-1.el7
Complete!
4、重置密码
查找原始密码
cat /var/log/mysqld.log |grep password
A temporary password is generated for root@localhost: %<klctp
mysql -u root -p
如果登录时出错
MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
执行如下命令
sudo chown -R openscanner:openscanner /var/lib/mysql
修改默认密码:
# 第一次需要重置密码
ALTER USER USER() IDENTIFIED BY '123456';
重置mysql 密码:
use mysql;
update user set authentication_string= password('123456') where user='root';
#authentication_string (有可能是password)需要 desc user
允许远程连接
grant all privileges on *.* to '用户名'@'%' identified by '密码' with grant option;
flush privileges;