mysql 5.7 安装及修改/重置密码
2017-07-03 14:52
856 查看
之前在小型机上装了feroda系统,装了mysql后,发现无法找到root用户密码,
mysqld_safe也不能用,最后发现一片文章,原来mysql5.7可以通过my.cnf配置文件设置不验证密码。记录下全文。
1、mysql安装检查:
如果已经有的话执行命令
2、先到mysql官网http://dev.mysql.com/downloads/mysql/下载5.7的安装包,download-yum选择
进入系统下载安装包:
mysqld_safe也不能用,最后发现一片文章,原来mysql5.7可以通过my.cnf配置文件设置不验证密码。记录下全文。
1、mysql安装检查:
yum list installed | grep mysql
如果已经有的话执行命令
yum -y remove mysql-libs.x86_64卸载已经安装的mysql。
2、先到mysql官网http://dev.mysql.com/downloads/mysql/下载5.7的安装包,download-yum选择
Red Hat Enterprise Linux 7 / Oracle Linux 7 (ArchitectureIndependent), RPM Package,
进入系统下载安装包:
wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm[/code]
如果新的系统还没有wget命令的话可以先:yum install wget
3、添加选择yum源:yum localinstall mysql57-community-release-el7-7.noarch.rpm yum repolist all | grep mysql
4、安装mysql:yum install mysql-community-server
5、安装完成之后会自动在log中生成连接的密码,
启动mysql:#service mysqld start
查看密码:#cat /var/log/mysqld.log |grep password >2016-08-23T02:33:48.872073Z 1 [Note] A temporary password isgenerated for root@localhost: %IrczkB+J7Ez
你必须重新设置密码才能执行语句[root@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. >ALTER USER USER() IDENTIFIED BY '需要设置安全等级很高的密码,否则报错'; #或者如下: >ALTER USER 'root'@'localhost' identified by '需要设置安全等级很高的密码,否则报错' password expire never;#这个错误是因为密码太简单 RROR 1819 (HY000): Your password does not satisfy the current policy requirements
6、重置 5.7 的密码很简单:
1) 修改/etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1
这一行配置让 mysqld 启动时不对密码进行验证2) 重启mysqld 服务:`service mysqld restart` 3) 使用 root 用户登录到 mysql:`mysql -u root ` 4) 切换到mysql数据库,更新 user 表:update user set authentication_string = password('123456'),password_expired = 'N', password_last_changed = now() where user = 'root';
在之前的版本中,密码字段的字段名是password,5.7版本改为了authentication_string5) 退出 mysql,编辑 `/etc/my.cnf` 文件,删除 `skip-grant-tables=1`的内容
7、重启mysqld 服务,再用新密码登录即可[root@mysqlA ~]# mysql -V mysql Ver 14.14 Distrib5.7.14, for Linux (x86_64) using EditLine wrapper
8、允许远程连接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 'password' with grant option;
9、修改密码多种方法
方法1: 用SET PASSWORD命令mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
方法2:用mysqladminmysqladmin -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;
方法4: 使用ALTER USER修改用户信息ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password' PASSWORD EXPIRE NEVER;
相关文章推荐
- CentOS 7 安装及卸载、重置登录密码 MySql5.7
- linux中的Mysql的安装、重置安装密码、修改权限
- MySql 5.7安装(随机密码,修改默认密码)
- CentOS 7.3 安装MySQL 5.7并修改初始密码
- MySql 5.7安装(随机密码,修改默认密码)两个坑
- MySql 5.7安装(随机密码,修改默认密码)
- CentOS7 安装 Mysql 5.7,密码查看与修改
- 一键安装MySQL 5.7与密码及策略修改
- MySQL 5.7安装完成后默认密码修改
- CentOS7 安装 Mysql 5.7,密码查看与修改
- ubuntu下mysql安装路径更改及密码修改及日志文件
- WAMP安装好后,mysql密码是为空的,那么要如何修改呢
- 安装好MySQL后,用SQL去修改root帐号的密码,结果不能登录了!
- CentOS 6.3 编译安装 MySQL 5.6.10 并修改MySQL的root用户密码
- ubuntu下mysql安装路径更改及密码修改
- mysql免安装版配置和密码修改
- Mysql 修改密码及重置密码方法
- 包安装失败 ! 无法修改密码,启动报错 ubuntu 12.10 下安装 mysql-5.5.28-linux2.6-x86_64 包,最终回到终端在线安装
- MySQL的root密码忘记,MySQL的root密码重置,MySQL的root密码修改
- Mysql安装后修改root密码