zoukankan      html  css  js  c++  java
  • 腾讯云主机安装登录mysql失败--解决方案[重置root密码并实现远程连接]

    登录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 &
    [1] 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工具远程连接,点击左下角的"连接测试",连接成功:

  • 相关阅读:
    Python从菜鸟到高手(2):清空Python控制台
    Python爬虫黑科技(经验)
    Python黑科技:6行代码轻松搭建FTP服务器
    Python黑科技:FuckIt.py
    Python黑科技:在家远程遥控公司电脑,python+微信一键连接!
    Python黑科技 | Python中四种运行其他程序的方式
    python3.x使用cxfreeze将.p打包成.exe
    【python 应用之四】提升 Python 运行性能的 7 个习惯
    JSF标签之f:facet 的使用方法
    windows快捷键之打开网络连接
  • 原文地址:https://www.cnblogs.com/jun1019/p/7063508.html
Copyright © 2011-2022 走看看