登录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. NYOJ----蛇形填数

    蛇形填数 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为: 10 11 12 1 9 16 ...

  2. MySQL备份与还原详细过程示例

    MySQL备份与还原详细过程示例 一.MySQL备份类型 1.热备份.温备份.冷备份 (根据服务器状态) 热备份:读.写不受影响: 温备份:仅可以执行读操作: 冷备份:离线备份:读.写操作均中止: 2 ...

  3. webpack window 安装loader

    1.安装loadernpm install css-loader style-loader --save-dev 2.配置loader,在webpack.config.js中 module: { lo ...

  4. C# Random 生成不重复随机数

    命名空间:System 表示伪随机数生成器,一种能够产生满足某些随机性统计要求的数字序列的设备. 伪随机数是以相同的概率从一组有限的数字中选取的.所选数字并不具有完全的随机性,因为它们是用一种确定的数 ...

  5. Spark弹性分布式数据集RDD

    RDD(Resilient Distributed Dataset)是Spark的最基本抽象,是对分布式内存的抽象使用,实现了以操作本地集合的方式来操作分布式数据集的抽象实现.RDD是Spark最核心 ...

  6. WinForm DataGridView新增加行

      1.不显示最下面的新行 通常 DataGridView 的最下面一行是用户新追加的行(行头显示 * ).如果不想让用户新追加行即不想显示该新行,可以将 DataGridView 对象的 Allow ...

  7. 【蓝桥杯】PREV-21 回文数字

    题目链接:http://lx.lanqiao.org/problem.page? gpid=T113   历届试题 回文数字   时间限制:1.0s   内存限制:256.0MB      问题描写叙 ...

  8. STM32的JTAG下载模式

    SWJ:串行线JTAG配置 (Serial wire JTAG configuration)  SWJ(串行线JTAG)支持JTAG或SWD访问Cortex的调试端口. 系统复位后的默认状态是启用SW ...

  9. 搭建MVC及WEB API项目框架时碰到的问题集合

    前言 刚开始创建MVC与Web API的混合项目时,碰到好多问题,今天拿出来跟大家一起分享下.有朋友私信我问项目的分层及文件夹结构在我的第一篇博客中没说清楚,那么接下来我就准备从这些文件怎么分文件夹说 ...

  10. django -- 联合索引

    一.定义: from django.db import models # Create your models here. class Person(models.Model): first_name ...