首先检查是否已经已经下载mysql安装包:
rpm -qa | grep mysql
如果存在则可以删除:
rpm -e xxxx xxxx表示包名称
下载mysql安装包:
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
然后安装mysql包:
yum -y install mysql57-community-release-el7-10.noarch.rpm
安装mysql:这里需要花点时间,耐心等待
yum -y install mysql-community-server
启动mysql:
systemctl start mysqld.service
停止:
systemctl stop mysqld.service
或
service mysql stop
如果要设置开机自启动mysql,使用以下命令:
systemctl enable mysqld.service
查看状态:
systemctl status mysqld
查看mysql的初始密码:如果能正常查看到,则OK;如果查看不到,则表示没有密码。
grep 'password' /var/log/mysqld.log
进入数据库:
mysql -u root -p
输入命令后,点击回车,会让你输入密码,然后输入刚刚的初始密码(输密码的时候不可见),当然支持粘贴,你可以复制初始密码后,然后粘贴。如果没有密码,直接回车即可。
修改密码语句:
##MySQL版本5.7.6版本以前用户可以使用如下命令:
SET PASSWORD = PASSWORD('你的密码');
##MySQL版本5.7.6版本开始的用户可以使用如下命令:
ALTER USER USER() IDENTIFIED BY '你的密码';
太简单会提示:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements.
退出:
exit
失败安装解决办法:
1. 提示:源 "MySQL 5.7 Community Server" 的 GPG 密钥已安装,但是不适用于此软件包。且执行 systemctl start mysqld.service 会出现 “ Failed to start mariadb.service: Unit not found.”
解决办法:
GPG验证不通过,可以理解为本机配置的这个软件包对应的公钥不对,签名验证失败。在mysql官网搜关键字GPG,找到了解决方案,大意是如果使用的4.1以上版本的rpm的话,除了import mysql的公钥到个人用户的配置中,还需要import mysql的公钥到RPM的配置中。
原文如下:MySQL :: MySQL 5.7 Reference Manual :: 2.1.4.4 Signature Checking Using RPMhttps://dev.mysql.com/doc/refman/5.7/en/checking-rpm-signature.html
If you are using RPM 4.1 and it complains about (GPG) NOT OK (MISSING KEYS: GPG#3a79bd29), even though you have imported the MySQL public build key into your own GPG keyring, you need to import the key into the RPM keyring first. RPM 4.1 no longer uses your personal GPG keyring (or GPG itself). Rather, RPM maintains a separate keyring because it is a system-wide application and a user’s GPG public keyring is a user-specific file. To import the MySQL public key into the RPM keyring, first obtain the key, then use rpm --import to import the key. For example:
$> gpg --export -a 3a79bd29 > 3a79bd29.asc
$> rpm --import 3a79bd29.asc
Alternatively, rpm also supports loading the key directly from a URL:
2. 如果执行命令过程中提示:Unable to find a match: mysql-community-server 可以通过命令解决
yum module disable mysql
3 .提示没有权限,执行下面语句赋予权限,然后重试。
chown mysql:mysql -R /var/lib/mysql
4.执行语句报错:mysql报错:You must reset your password using ALTER USER statement before executing this statement.
需要重置密码。
5. 密码太简单不让设置问题就解决:
## 查看密码验证策略
show variables like 'validate_password%'
validate_password_policy取值
0 or LOW :只验证长度
1 or MEDIUM : 验证长度、数字、大小写、特殊字符
2 or STRONG : 验证长度、数字、大小写、特殊字符、字典文件
修改策略,及密码长度
# 修改 策略
set global validate_password_policy=0;
#修改长度
set global validate_password_length=6;
在从新设置即可。