设为首页 收藏本站
查看: 987|回复: 0

[经验分享] CentOS7 安装 Mysql 5.7,密码查看与修改

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-24 09:21:02 | 显示全部楼层 |阅读模式
1、检测下系统有没有自带的mysql:yum list installed | grep mysql,
如果已经有的话执行命令yum -y remove mysql-libs.x86_64卸载已经安装的mysql。

http://dev.mysql.com/downloads/mysql/
2、先到mysql官网下载5.7.11的安装包,download-yum选择Red Hat Enterprise Linux 7 / Oracle Linux 7 (ArchitectureIndependent), RPM Package ,
进入系统下载安装包:


1
#wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm




如果新的系统还没有wget命令的话可以先:
1
#yum install wget




3、添加选择yum源:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#yum localinstall mysql57-community-release-el7-7.noarch.rpm
Running transaction
  正在安装    : mysql57-community-release-el7-7.noarch                         1/1
  验证中      : mysql57-community-release-el7-7.noarch                         1/1

已安装:
  mysql57-community-release.noarch 0:el7-7                                         

完毕!

#yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community         启用:    21
mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用
mysql-tools-community/x86_64      MySQL Tools Community              启用:    36
mysql-tools-community-source      MySQL Tools Community - Source     禁用
mysql55-community/x86_64          MySQL 5.5 Community Server         禁用
mysql55-community-source          MySQL 5.5 Community Server - Sourc 禁用
mysql56-community/x86_64          MySQL 5.6 Community Server         禁用
mysql56-community-source          MySQL 5.6 Community Server - Sourc 禁用
mysql57-community/x86_64          MySQL 5.7 Community Server         启用:   110
mysql57-community-source          MySQL 5.7 Community Server - Sourc 禁用




4、安装mysql:
1
2
3
4
5
6
7
8
9
10
11
#yum install mysql-community-server
已安装:
  mysql-community-libs.x86_64 0:5.7.14-1.el7            mysql-community-libs-compat.x86_64 0:5.7.14-1.el7            mysql-community-server.x86_64 0:5.7.14-1.el7           

作为依赖被安装:
  mysql-community-client.x86_64 0:5.7.14-1.el7                                         mysql-community-common.x86_64 0:5.7.14-1.el7                                       

替代:
  mariadb-libs.x86_64 1:5.5.44-2.el7.centos                                                                                                                                 

完毕!




5、安装完成之后会自动在log中生成连接的密码,

启动mysql:

1
#systemctl start mysqld




查看密码:
1
2
[iyunv@mysqlA ~]# cat /var/log/mysqld.log |grep password
2016-08-23T02:33:48.872073Z 1 [Note] A temporary password isgenerated for root@localhost: %IrczkB+J7Ez





你必须重新设置密码才能执行语句
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@mysqlA ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.14
Copyright (c) 2000, 2016, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.




6、其实想要重置 5.7 的密码很简单,就一层窗户纸:
    1)   修改/etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1
    这一行配置让 mysqld 启动时不对密码进行验证

    2)   重启mysqld 服务:systemctl restart mysqld

    3)   使用 root 用户登录到 mysql:mysql -uroot

    4)   切换到mysql数据库,更新 user 表:
          update user set authentication_string = password('123456'),password_expired = 'N', password_last_changed = now() where user = 'root';
在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication_string

    5)   退出 mysql,编辑 /etc/my.cnf 文件,删除 skip-grant-tables=1的内容

7、重启mysqld 服务,再用新密码登录即可


1
2
[iyunv@mysqlA ~]# mysql -V
mysql  Ver 14.14 Distrib5.7.14, for Linux (x86_64) using EditLine wrapper





8、允许远程连接

1
2
3
4
5
6
7
8
9
mysql> select user,host from mysql.user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| mysql.sys | localhost |
| root      | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)
mysql>grant all privileges on *.* to 'root'@'%' identified by 'r0b0t.RQB' with grant option;




9、修改密码多种方法

    方法1: 用SET PASSWORD命令

      mysql -u root

      mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');


    方法2:用mysqladmin

      mysqladmin -u root password "newpass"

      如果root已经设置过密码,采用如下方法

      mysqladmin -u root password oldpass "newpass"


    方法3: 用UPDATE直接编辑user表

      mysql -u root

      mysql> use mysql;

      mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

      mysql> FLUSH PRIVILEGES;


    在丢失root密码的时候,可以这样

      mysqld_safe --skip-grant-tables&

      mysql -u root mysql

      mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

      mysql> FLUSH PRIVILEGES;




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-262171-1-1.html 上篇帖子: mysql 最基础的日常操作 下篇帖子: 搭建mysql的主从复制和读写分离 密码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表