二进制方式安装mysql

下载官方打包好的rpm的集合

https://downloads.mysql.com/archives/get/file/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

[root@xuegod63 opt]# tar xf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

解压出来,发现有很多rpm包,我们需要用到的包是:

mysql-community-common-5.7.20-1.el7.x86_64.rpm

mysql-community-libs-5.7.20-1.el7.x86_64.rpm

mysql-community-client-5.7.20-1.el7.x86_64.rpm

mysql-community-server-5.7.20-1.el7.x86_64.rpm

依次安装:

yum install mysql-community-common-5.7.20-1.el7.x86_64.rpm -y

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忘记密码

解决方法

  • 第一步:打开mysql5.7的配置文件my.cnf,并在里面增加一行:skip-grant-tables   保存并退出(:wq)
[root@iz09a32x1sghz3z ~]# vi /etc/my.cnf
  • 第二步:重启mysql
[root@iz09a32x1sghz3z ~]# service mysqld restart
  • 第三步:登录mysql并且修改密码

用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" ;

  • 第四步:打开mysql5.7的配置文件my.cnf,把刚增加这行:skip-grant-tables  删除掉 保存并退出(:wq)

Table 2.11 MySQL Installation Layout for Linux RPM Packages from the MySQL Developer Zone

Files or ResourcesLocation
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:/var/log/mysqld.log

For SLES: /var/log/mysql/mysqld.log

Value of secure_file_priv /var/lib/mysql-files
System V init script

For RHEL, Oracle Linux, CentOS or Fedora platforms: /etc/init.d/mysqld

For SLES: /etc/init.d/mysql

Systemd service

For RHEL, Oracle Linux, CentOS or Fedora platforms: mysqld

For SLES: mysql

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!';
原文地址:https://www.cnblogs.com/xiaofeng666/p/10999607.html