下载官方打包好的rpm的集合html
https://downloads.mysql.com/archives/get/file/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tarnode
[root@xuegod63 opt]# tar xf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tarmysql
解压出来,发现有不少rpm包,咱们须要用到的包是:linux
mysql-community-common-5.7.20-1.el7.x86_64.rpmsql
mysql-community-libs-5.7.20-1.el7.x86_64.rpmshell
mysql-community-client-5.7.20-1.el7.x86_64.rpm数据库
mysql-community-server-5.7.20-1.el7.x86_64.rpm安全
依次安装:app
yum install mysql-community-common-5.7.20-1.el7.x86_64.rpm -yui
yum install mysql-community-libs-5.7.20-1.el7.x86_64.rpm -y
yum install mysql-community-client-5.7.20-1.el7.x86_64.rpm -y
yum install mysql-community-server-5.7.20-1.el7.x86_64.rpm -y
注意安装 mysql-community-server-5.7.20-1.el7.x86_64.rpm报错
[root@b mysql-5.7.26]# yum install mysql-community-server-5.7.26-1.el6.x86_64.rp m -y
Error: Package: mysql-community-server-5.7.26-1.el6.x86_64 (/mysql-community-ser ver-5.7.26-1.el6.x86_64)
Requires: libsasl2.so.2()(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
[root@b mysql-5.7.26]# rpm -ivh mysql-community-server-5.7.26-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.26-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libsasl2.so.2()(64bit) is needed by mysql-community-server-5.7.26-1.el6.x86_64
缘由:这是因为yum安装了旧版本的GPG keys形成的 解决办法: --force --nodeps
[root@b mysql-5.7.26]# rpm -ivh mysql-community-server-5.7.26-1.el6.x86_64.rpm --force --nodeps
warning: mysql-community-server-5.7.26-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.26-1.e################################# [100%]
(注意:安装顺序不能错,不然会报错依赖包没有安装)
查看安装路径:
[root@xuegod63 opt]# rpm -ql mysql-community-server
能够看到数据库安装在/var/lib/mysql 目录下
启动服务:
[root@xuegod63 opt]# systemctl start mysqld.service
获取临时密码:
第一次经过# grep "password" /var/log/mysqld.log 命令获取MySQL的临时密码
用该密码登陆到服务端后,必须立刻修改密码,否则操做查询时报错误
[root@xuegod63 opt]# grep "password" /var/log/mysqld.log
2017-11-10T14:38:40.930543Z 1 [Note] A temporary password is generated for root@localhost: itBp#lFva0aY
补充注意:MySQL5.7以前的版权,初次安装MySQL,默认登录密码是空,5.7以后的版本,默认登录的密码为一个随机生产的字符串,存在/var/log/mysqld.log 文件里。
安全初始化操做:
[root@xuegod65 opt]# mysql_secure_installation
修改默认密码和相关的权限
MySQL5.7对密码复杂度要求比较高,刚开始设置的密码必须符合长度(默认最小长度的8),且必须含有数字,小写或大写字母,特殊字符。
这也是从安全考虑,但愿使用者不要强行修改密码策略,设置简单的密码
Welcome1qazx@com
若是想设置简单密码,以下操做:
[root@localhost ~]# mysql -uroot -p' itBp#lFva0aY '
方法一:首先,修改validate_password_policy参数的值
mysql> set global validate_password_policy=0; #定义复杂度
mysql> set global validate_password_length=1; #定义长度 默认是8
方法二:在/etc/my.cnf 可关闭密码强度审计插件,重启mysql服务
validate_password=ON/OFF/FORCE/FORCE_PLUS_PERMANENT: 决定是否使用该插件(及强制/永久强制使用)。
修改密码
mysql>
set password for 'root'@'localhost'=password('123456'); 修改root帐号登录密码
Query OK, 0 rows affected, 1 warning (0.05 sec)
刷新权限表(使更改密码当即生效而不用重启mysql)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
登录linux下的mysql5.7忘记密码
解决方法
[root@iz09a32x1sghz3z ~]# vi /etc/my.cnf
[root@iz09a32x1sghz3z ~]# service mysqld restart
用root帐号登陆: [root@iz09a32x1sghz3z ~]# mysql -u root
使用mysql中的mysql数据库: mysql> use mysql;
修改密码: update user set authentication_string = password("Szfore_68638") where user="root" ;
刷新数据库: flush privileges;
退出: quit;
注意:mysql5.7的user表中的password字段已经改为了authentication_string 字段了。
这时候,须要输入的命令是update user set authentication_string = password("Szfore_68638") where user="root" ;
Table 2.11 MySQL Installation Layout for Linux RPM Packages from the MySQL Developer Zone
Files or Resources | Location |
---|---|
Client programs and scripts | /usr/bin |
mysqld server | /usr/sbin |
Configuration file | /etc/my.cnf |
Data directory | /var/lib/mysql |
Error log file | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Value of secure_file_priv |
/var/lib/mysql-files |
System V init script | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Systemd service | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Pid file | /var/run/mysql/mysqld.pid |
Socket | /var/lib/mysql/mysql.sock |
Keyring directory | /var/lib/mysql-keyring |
Unix manual pages | /usr/share/man |
Include (header) files | /usr/include/mysql |
Libraries | /usr/lib/mysql |
Miscellaneous support files (for example, error messages, and character set files) | /usr/share/mysql |
RHEL, Oracle Linux, CentOS, and Fedora systems:
shell> sudo grep 'temporary password' /var/log/mysqld.log
The next step is to log in with the generated, temporary password and set a custom password for the superuser account:
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';