linux(ubuntu)Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'解决方法

本文介绍了当遇到MySQL登录权限被拒错误时的一种解决方案。通过停止MySQL服务并使用特定参数重新启动来绕过授权表,进而重置root用户的密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在自己的机子上部署vj的时候上不去mysql数据库,通过以下两行命令轻松解决:

问题:

ttop@ttop-Lenovo:~$ mysql -u root -prootpass
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

解决:

root@ttop-Lenovo:/home/ttop# /etc/init.d/mysql stop

Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql stop

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) utility, e.g. stop mysql
mysql stop/waiting
root@ttop-Lenovo:/home/ttop# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 5598
root@ttop-Lenovo:/home/ttop# 140807 18:54:42 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
140807 18:54:42 mysqld_safe Logging to '/var/log/mysql/error.log'.
140807 18:54:42 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

root@ttop-Lenovo:/home/ttop#

root@ttop-Lenovo:/home/ttop# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.38-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2014, 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>




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值