登录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. oracle安装后tnsnames.ora内容

    # tnsnames.ora Network Configuration File: D:\Develop\oracle11g\product\11.2.0\dbhome_1\network\admi ...

  2. hihocoder 1638:多级并查集

    题目链接 并查集可以用于聚类. import java.io.FileInputStream; import java.io.FileNotFoundException; import java.ut ...

  3. 解决编译Apache出现的问题:configure: error: APR not found

    今日编译apache时出错: #./configure --prefix……检查编辑环境时出现: checking for APR... noconfigure: error: APR not fou ...

  4. CentOS 7.0关闭默认firewall防火墙启用iptables防火墙

    操作系统环境:CentOS Linux release 7.0.1406(Core) 64位CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤. 1.关闭f ...

  5. [Android实例] Android之断点续传下载

    在我们做开发的时候经常遇到的就是下载了,现在下载的方法有很多很多,那么怎么做到断点续传下载呢!很多人都头疼这个问题,如果我们没有很好的逻辑真不是很容易解决啊.我参考了一下前辈们的资料了整理了一个项目, ...

  6. 【MyBatis】MyBatis之分页

    关于MyBatis的搭建可以参见“MyBatis的配置”,MyBatis是对JDBC底层代码的封装,关于Oracle.MySQL.SqlServer的分页可以查看Oracle.SqlServer.My ...

  7. Junit 4.x 单元测试,参数化测试,套件测试 实例

    对下面三个类进行单元测试 ,组成套件测试. public class Calculate { public int add(int a, int b) { return a + b; } public ...

  8. sqlserver不太常见的,可能常见但又疑问的tsql语句

    2013年10月29日16:01:58 当数据有 time类型列时候,比如 打电话的通话时长,我们查询时候不方便,我们可以添加一个冗余列,直接统计秒 ,但是 后期知道的,现在我把例如 00:12:23 ...

  9. 忙里偷闲写的小例子---读取android根目录下的文件或文件夹

    最近几天真的是各种意义上的忙,忙着考试,还要忙着课程设计,手上又有外包的项目,另一边学校的项目还要搞,自己的东西还在文档阶段,真的是让人想死啊!! 近半个月来,C#这方面的编码比较多,android和 ...

  10. cucumber java从入门到精通(2)用代码定义步骤

    cucumber java从入门到精通(2)用代码定义步骤 上一节里我们定义了feature文件,feature文件就是自然语言描述的用例文件,它有一定的章法,具体的潜规则是: 使用Feature关键 ...