登陸MySQL時報錯:Access denied for user 'root'@'localhost' (using password: YES)mysql
解決步驟:sql
一、使用ssh工具鏈接主機,使用mysqld_safe命令進入安全模式:centos
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
二、再打開一個窗口,鏈接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 ~]#
三、打開遠程鏈接權限:ssh
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>
四、使用Navicat工具遠程鏈接,點擊左下角的"鏈接測試",鏈接成功:工具