- View yum has several mysql packages
yum repolist all | grep mysql
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server disabled
!mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 564
mysql57-community-source MySQL 5.7 Community Server disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server disabled
If not, we manually download an installation package such as version 5.7
# 下载安装包
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
# 解压
rpm -ivh mysql-community-release-el7-5.noarch.rpm
- Check which version of mysql is currently downloaded by yum by default
yum repolist enabled | grep "mysql.*-community.*"
# 可以看到默认输出是 5.7
!mysql-connectors-community/x86_64 MySQL Connectors Community 230
!mysql-tools-community/x86_64 MySQL Tools Community 138
!mysql57-community/x86_64 MySQL 5.7 Community Server 564
- Change yum settings to download the mysql version by default
# 将你想要的下载版本设置 enable = 1 即可。
# 注意:只有一个版本设置为 enbale = 1 其它必须得设为 0。
vim /etc/yum.repos.d/mysql-community.repo
- start download
# 由于我们设置为 5.7 设置好 enable = 1 ,所以会自动下载 5.7 版本。
yum install mysql-community-server
- start service
systemctl start mysqld
systemctl status mysqld
- get temporary password
grep 'temporary password' /var/log/mysqld.log
If no temporary password is displayed, you can directly enter it to reset it.
mysql_secure_installation
If there is still no way to get the password, then use the ultimate method:
systemctl stop mysqld
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
systemctl start mysqld
mysql -u root
use mysql;
update user set authentication_string=PASSWORD("新密码") where User='root';
flush privileges;
exit
systemctl unset-environment MYSQLD_OPTS
systemctl stop mysqld
systemctl start mysqld
This method is valid for both forgotten password and reset password. The principle is to log in directly to mysql by --skip-grant-tables
closing the user password authentication.
Well, this is probably the download and password initialization process of centos 7 mysql, I hope it will be helpful to you.