登录MySQL时报错:Access denied for user 'root'@'localhost' (using password: YES)

解决步骤:

1、使用ssh工具连接主机,使用mysqld_safe命令进入安全模式:

Last login: Thu Jun 22 09:56:57 2017 from 182.50.118.228
[root@VM_219_131_centos ~]# service msyqld status
msyqld: unrecognized service
[root@VM_219_131_centos ~]# service mysqld stop
Stopping mysqld: [ OK ]
[root@VM_219_131_centos ~]# service msyqld status
msyqld: unrecognized service
[root@VM_219_131_centos ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[] 4436
[root@VM_219_131_centos ~]# 170622 09:58:15 mysqld_safe Logging to '/var/log/mysqld.log'.
170622 09:58:15 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
170622 10:02:45 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

2、再打开一个窗口,连接MySQL,就可以为root用户设置密码了:

Last login: Thu Jun 22 09:57:25 2017 from 182.50.118.228
[root@VM_219_131_centos ~]# mysql -uroot mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, 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> UPDATE user SET Password=PASSWORD('你的密码') where USER='root' and host='root' or host='localhost';
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0 mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) mysql> quit
Bye
[root@VM_219_131_centos ~]#

3、打开远程连接权限:

Last login: Thu Jun 22 09:58:24 2017 from 182.50.118.228
[root@VM_219_131_centos ~]# service mysqld status
mysqld (pid 4532) is running...
[root@VM_219_131_centos ~]# service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[root@VM_219_131_centos ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, 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 |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec) mysql>

4、使用Navicat工具远程连接,点击左下角的"连接测试",连接成功:

腾讯云主机安装登录mysql失败--解决方案[重置root密码并实现远程连接]的更多相关文章

  1. Ubuntu腾讯云主机安装分布式memcache服务器,C#中连接云主机进行存储的示例

    Ubuntu腾讯云主机安装分布式memcache服务器,C#中连接云主机进行存储的示例(github代码:https://github.com/qq719862911/MemcacheTestDemo ...

  2. 【转】CentOS6下安装mysql后,重置root密码方法

    本文转自:CentOS6下安装mysql后,重置root密码方法 centos下安装mysql,居然不知道root用户密码,本想重装,不过还是先度娘了一些,发现这篇文章,刚好解决我的燃眉之急,太赞了. ...

  3. 腾讯云ubuntu安装使用MySQL

    安装步骤 ubuntu@VM---ubuntu:~$ sudo apt-get install mysql-server (密码: root/root) ubuntu@VM---ubuntu:~$ s ...

  4. Navicat连接远程主机(腾讯云服务器)的mysql失败,解决

    赋予所有用户远程连接的权限,重启mysql即可连接成功: grant all privileges on . to 'root'@'%' identified by 'admin'; systemct ...

  5. MySql 5.7 重置root密码

    一.以安全模式登录 # Stop MySQL sudo service mysql stop # Make MySQL service directory. sudo mkdir -p /var/ru ...

  6. 腾讯云主机 MySQL 远程访问配置方法

    使用腾讯云主机安装 MySQL 之后,需要通过以下步骤进行配置以实现远程访问,主要分为两大部分 一.服务器端口配置 1.如果你的云主机配置了安全组,如果没有配置安全组就可以直接跳过“步骤1”的操作,否 ...

  7. 访问腾讯云主机mysql的设置问题

    ---恢复内容开始--- 1.需要打开腾讯云主机的防火墙端口3306,具体实现可以在腾讯云控制台安全组中设置开放全部端口(安全组对应入站.出战规则): 2.将云主机mysql中mysql数据库user ...

  8. 腾讯云 ubuntuservermysql安装和外网訪问

    1 腾讯云 购买ubuntu 默认账户是ubuntu(因为winscp 使用ubuntu没有权限写文件) 因为腾讯云主机ubuntu系统默认username为ubuntu,不喜欢每次做什么都要sudo ...

  9. 腾讯云-ASP.NET Core+Mysql+Jexus+CDN上云实践

    腾讯云-ASP.NET Core+Mysql+Jexus+CDN上云实践.md 开通腾讯云服务器和Mysql 知识点: ASP.NET Core和 Entity Framework Core的使用 L ...

随机推荐

  1. [转载]eclipse的远程调试功能配置

    原文地址:eclipse的远程调试功能配置作者:我的 用途:web应用部署并运行于外部(区别于eclipse环境中启动的)应用服务器中,当出现问题时,可以使用eclipse工程的源代码进行跟踪调试. ...

  2. 【转】IOCP创建

    转自:http://www.cmnsoft.com/wordpress/?p=248 感谢原作者.我在此整理一下: 完成端口(IOCP)是WINDOWS平台上特有的一种技术.要使用IOCP技术,就要用 ...

  3. 搭建自己的 github.io 博客

    1.前言 github.io 是基于 Github 的 repo 管理,这意味着咱们对其是有绝对的控制,这个跟放在第三方的平台比,可控性要好太多. 使用 github pages 服务搭建博客的好处有 ...

  4. formValidator输入验证、异步验证实例 + licenseImage验证码插件实例应用

    实例技术:springmvc 实现功能:完整用户登录流程.输入信息规则校验.验证码异步校验. 功能清单: 1.springmvc控制器处理get请求(/member/login.html),进行静态页 ...

  5. hadoop相关内容

    数据库导出到hadoop http://www.ibm.com/developerworks/cn/data/library/techarticle/dm-1212liuqy/ http://www. ...

  6. cors的实现原理

    如何辨认一个请求的源domain? 如何发送和处理cors请求? 优势 和 弱点 cookie 和 伪装 1. http://www.staticapps.org/articles/cross-dom ...

  7. sql 置顶功能的查询

    sql中有置顶的需求,文章很多条,分页查询,要求置顶的在最前面: 只需要使用: order by 置顶字段 即可

  8. 探索MVP(Model-View-Presenter)设计模式在SharePoint平台下的实现

    对于SharePoint Developers来说,往往会过多的去关注SharePoint平台和工具,而把设计模式和代码的可测试性放在了一个较低的优先级.这并不是说SharePoint Develop ...

  9. SQL 给字符串补0

    第一种方法: right('00000'+cast(@count as varchar),5) 其中'00000'的个数为right函数的最后参数,例如这里是5,所以有5个0 @count就是被格式化 ...

  10. C#基础第一天-作业答案

    题一答案: Console.WriteLine("请输入a"); int a = Convert.ToInt32(Console.ReadLine()); Console.Writ ...