centos7 下安装rpm的mysql 5.7

在centos7下安装mysql5.7

一:下载mysql 去官网上去下载;这里我下载的二进制格式的

         https://dev.mysql.com/downloads/mysql/ 去下载对应平台的mysql版本

 

二:解压mysql并采用yum安装本地rpm方式

[root@xuegod63 ~]# unzip mysql5.7.zip 
Archive:  mysql5.7.zip
  inflating: mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm  
  inflating: mysql-community-server-5.7.20-1.el7.x86_64.rpm  
  inflating: mysql-community-client-5.7.20-1.el7.x86_64.rpm  
  inflating: mysql-community-common-5.7.20-1.el7.x86_64.rpm  
  inflating: mysql-community-libs-5.7.20-1.el7.x86_64.rpm  
[root@xuegod63 ~]# yum -y localinstall ./*.rpm

 

三:启动mysql服务 并查看是否启动成功;看到有3306就代表启动成功

[root@xuegod63 ~]# systemctl start mysqld
[root@xuegod63 ~]# ss -tnl
State       Recv-Q Send-Q                                      Local Address:Port                                                     Peer Address:Port              
LISTEN      0      128                                                     *:22                                                                  *:*                  
LISTEN      0      100                                             127.0.0.1:25                                                                  *:*                  
LISTEN      0      128                                                    :::22                                                                 :::*                  
LISTEN      0      100                                                   ::1:25                                                                 :::*                  
LISTEN      0      80                                                     :::3306                                                               :::*     

 

四:启动mysql 报错解决mysql密码问题  

这时候可以看见是失败的;因为mysql5.7默认是不可以直接登录的;这里我们给出了两种解决方式:

4.1:第一种解决mysql5.7初启动密码问题

[root@xuegod63 ~]# grep "password" /var/log/mysqld.log 
2017-12-12T11:07:34.808179Z 1 [Note] A temporary 
password is generated for root@localhost: %aqY==#QD7+s 这是临时获取的密码等会 登录使用 2017-12-12T11:09:50.817347Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO) [root@xuegod63 ~]# mysql -uroot -hlocalhost -p%aqY==#QD7+s
[这里要不能登录的话就 mysql -uroot -hlocalhost -p 去手动输入密码] mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor.
Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 Copyright (c) 2000, 2017, Oracle
and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c'
to clear the current input statement.
mysql>


  

第一次通过# grep "password" /var/log/mysqld.log 命令获取MySQL的临时密码
用该密码登录到服务端后,必须马上修改密码,不然操作查询时报错误
刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
如果想设置简单密码,如下操作:
方法一:首先,修改validate_password_policy参数的值
mysql> set global validate_password_policy=0; #定义复杂度
mysql> set global validate_password_length=1; #定义长度 默认是8
mysql>set password for 'root'@'localhost'=password('123456');

方法二:在/etc/my.cnf 可关闭密码强度审计插件,重启mysql服务
validate-password=ON/OFF/FORCE/FORCE_PLUS_PERMANENT: 决定是否使用该插件(及强制/永久强制使用)。

 

4.2:第二种解决mysql5.7初启动密码问题

MySQL5.7的跳过授权表登录。mysql启动时跳过授权表,使用无密码登陆,在这个会话中再把授权表加载进来,把密码修改之后重启即可。
1.关闭MySQL数据库
[root@localhost ~]# systemctl stop mysqld
Redirecting to /bin/systemctl stop mysqld.service
[root@localhost ~]# mysqld --help
[root@localhost ~]# mysqld --verbose --help >a.txt
加上--skip-grant-tables这个参数重启时,便可以跳过密码验证这个参数。
--skip-grant-tables (Start without grant tables. This gives all users FULL ACCESS to all tables.)
2.进入/etc/my.cnf配置文件把 validate_password=off参数注释掉。(如果有的话)
3.先执行
[root@localhost ~]# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
([root@localhost ~]# mysqld_safe --skip-grant-tables & 当此命令没有时使用上面的命令)
[root@localhost ~]# systemctl start mysqld 来启动数据库。
4.查看数据库是否启动 netstat -tunlp | grep 3306
5.使用mysql -u root 直接进行登陆
6.等进去之后执行 mysql> flush PRIVILEGES;
7.重新设置密码 mysql> alter user 'root'@'localhost' identified by '1234567';
8.执行 mysql> flush tables; 并推出
9.重启mysql的服务并登陆

 

  

 

posted @ 2017-12-12 19:24  你是我的神奇  阅读(2919)  评论(0编辑  收藏  举报