MYSQL登錄錯誤:mysqladmin: connect to server at 'localhost' failed
1.mysql登錄錯誤
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
無法修改密碼
用 service mysqld stop 輸入 mysql -uroot -p 回車進入 輸入原密碼 > use mysql; > update user set password=PASSWORD("long.com")where user="root"; > 更改密碼為 long.com > flush privileges; #更新權限 > quit 退出 service mysqld restart mysql -uroot -p新密碼進入
二,忘記本地root的登錄密碼
解決過程:
1、編輯/etc/my.cnf
在[mysqld] 配置部分添加一行
skip-grant-tables
2、保存后重啟mysql
[root@web02 etc]# service mysqld restart
Shutting down MySQL. [ OK ]
Starting MySQL. [ OK ]
3、登錄數據庫重新設置root密碼
[root@web02 ~]# mysql -uroot -p mysql
Enter password:
直接回車進入
執行下列語句
mysql> update user set password=password("mysql") where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
如果執行上一條報錯如下:
mysql> update user set password=password("123") where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
#錯誤的原因是 5.7版本下的mysql數據庫下已經沒有password這個字段了,password字段改成了authentication_string
則改用:
mysql> update mysql.user set authentication_string=password('123') where user='root';
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4、刪除/etc/my.cnf文件中添加的“skip-grant-tables”行,重啟mysql;
用新設的密碼就能正常登錄了;