mysql修改密码小步骤

错误分析:
一开始是密码错误导致,先添加skip-grant-tables(这个配置无视权限的,添加直接回车登录即可),尽心修改密码,发现错误照旧
百度了一下,发现是mysql数据权限问题
因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候 是虽然用的是root,
但实际是匿名登录的,通过错误提示里的''@'localhost'可以看出来

Centos 7 系统为例:

在 [mysqld] 添加 skip-grant-tables
[root@centos001 install]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 # Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

重启命令:service mysqld restart 重启Mysql服务
mysql -uroot -p 回车即可
[root@centos001 install]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.36 MySQL Community Server (GPL) 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>

修改密码:
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
28 rows in set (0.00 sec) mysql> UPDATE user SET password=PASSWORD('badaokeji') WHERE user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0 修改密码成功!
刷新数据裤:
FLUSH PRIVILEGES;

登录Mysql

删除我mysql的skip-grant-tables配置

[root@centos001 install]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 重启mysql:
service mysqld restart mysql -uroot -pbadaokeji
登录成功!!




登录mysql发现错误:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
密码正确还是无法登录

mysql数据权限问题

[root@centos001 install]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@centos001 install]# 那么就是我们的Mysql数据库问题
我们继续在/etc/my.con添加:
[mysqld]
skip-grant-tables 重启mysql:
service mysqld restart

重新登陆Mysql
[root@centos001 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.36 MySQL Community Server (GPL) 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec) mysql> exit; 百度了一下,发现是mysql数据权限问题
因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候 是虽然用的是root,
但实际是匿名登录的,通过错误提示里的''@'localhost'可以看出来

修改Mysql权限
添加无视权限配置: /etc/my.cof
[root@centos001 ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld]
skip-grant-table
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock 登录Mysql:
[root@centos001 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36 MySQL Community Server (GPL) 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ambari |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec) mysql> use msyq;
ERROR 1049 (42000): Unknown database 'msyq'
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database change
mysql> delete from user where USER='';
Query OK, 2 rows affected (0.00 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> \q
Bye 删除 skip-grant-table 配置
[root@centos001 ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock 重启Mysql
[root@centos001 ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@centos001 ~]# 重新登录Mysql:
root@centos001 ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@centos001 ~]# mysql -uroot -p
Enter password:
[root@centos001 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.36 MySQL Community Server (GPL) 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ambari |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec) mysql>

Mysql修改密码以及权限问题的更多相关文章

  1. 使用Mysql修改密码命令更改root的密码

    使用Mysql修改密码命令更改root的密码. 进入Mysql数据库命令行方式有两种方式: 方式一:在Mysql开始菜单里包含Mysql命令行客户端,只要点击输入root的密码即可进入. 方式二:在D ...

  2. Linux mysql 修改密码 三种方式(转载)

    注明:本文为转载,原文地址:https://www.cnblogs.com/chuckjam/archive/2018/08/10/9456255.html 前言 有时我们会忘记Mysql的密码,或者 ...

  3. MySql:mysql修改密码及配置远程连接

    通过配置文件修改 mysql5.7  mysql库下面的user表没有password字段无法修改密码,5.7版本已经不再使用password来作为密码的字段了  而改成了authentication ...

  4. Mysql 修改密码及重置密码方法

    修改密码: //选择数据库 use mysql; //修改密码 update user set password=password('新密码') where user='root'; //立即生效 f ...

  5. MySQL修改密码的三种方法

      MySQL修改密码的三种方法 1.方法1: 2.方法2: 3.方法3:        

  6. MySQL修改密码方法汇总

    本文给大家汇总介绍了MySQL修改密码的方法,分为MySQL5.7版本之前以及MySQL5.7版本之后的修改方法,有需要的小伙伴可以参考下 MySQL5.7版本之前修改密码的方法: 方法1: 用SET ...

  7. mysql数据库如何修改密码及权限分配

    如何修改Mysql密码 Mysql用户密码采用md5加密函数加密(单向加密) SELECT PASSWORD('root'); -- *81F5E21E35407D884A6CD4A731AEBFB6 ...

  8. mysql 修改密码 开启远程访问权限

    修改密码 update user set password=password('') where user='root'; FLUSH   PRIVILEGES; 远程访问权限: GRANT ALL ...

  9. Linux下 刚安装完mysql 修改密码

    在Centos中安装MySQL后默认的是没有root密码的,默认的是回车, 那么为了方便需要修改密码. 没有密码为MYSQL加密码: mysql -uroot -p 回车 提示输入密码,为空回车 up ...

随机推荐

  1. MySQL 8.0复制性能的提升(翻译)

    What’s New With MySQL Replication in MySQL 8.0 MySQL复制从问世到现在已经经历了多个年头,它的稳定性和可靠性也在稳步的提高.这是一个不停进化的过程,由 ...

  2. JDBC连接数据库反射实现O/R映射

    测试preparedStatement public void testPreparedStatement(){ Connection connection=null; PreparedStateme ...

  3. 申请MVP奖励时的小Tips

    大家新年好,今天MSPrecious为大家带来一些申请MVP奖励时的小Tips.   本文分为三个部分 MVP是什么 如何申请MVP 申请MVP需要注意的事项 MVP是什么? 我想,点进来看这篇文章的 ...

  4. hql to_number

    select max(cast(o.ordernum,int)) from className o or select max(cast(o.ordernum as int)) from classN ...

  5. PhoneGap 白名单安全机制 navigator.app 加载外部页面返回以及退出介绍

    一. Phonegap 白名单安全机制 Phonegap应用的页面大多存在于本地,但有时需要加载外部的Web页面到应用内置的浏览器 视图中已完成特定的应用功能,出于安全性考虑,PhoneGap 设立了 ...

  6. hdu-3397 Sequence operation 线段树多种标记

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3397 题目大意: 0 a b表示a-b区间置为0 1 a b表示a-b区间置为1 2 a b表示a- ...

  7. 20165302 预备作业3 Linux安装及学习

    linux系统安装 我在安装VirtualBox时出现了一些小问题,如图 我的电脑只能设置32-bit的Ubuntu版本,但教程上说要选用64-bit的,我通过百度查询得知要进行BIOS设置,设置好后 ...

  8. 关于python线程池threadpool

    #coding=utf-8 import time import threadpool def wait_time(n): print('%d\n' % n) time.sleep(2) #在线程池中 ...

  9. 在 Linux 下搭建 Git 服务器(yum安装)

    服务端(linux): 1. 安装git [root@localhost ~]# yum -y install git 2. 增加一个git账户 为了管理的方便,在linux下面增添一个 " ...

  10. 错误的另一个常见原因是默认的安全组规则。default security group默认情况下不允许ICMP(ping命令使用的协议)

    可以在openstack horizon界面中添加ICMP和ssh(TCP)规则,也可以通过命令行.命令行方式给默认安全组添加规则的方法如下: $ nova secgroup-add-rule def ...