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

系统:Centos 6.5 64位

Mysql:5.1.73

今天想做个数据库测试实验,居然忘记了Mysql数据的密码。于是使用安全模式启用。

[[email protected] ~]# service mysqld stop    #先停止数据库

Stopping mysqld:                                           [  OK  ]

[[email protected] ~]# mysqld_safe --skip-grant-tables &    #利用安全模式启用数据库

[1] 1547

[[email protected] ~]# 150403 10:43:26 mysqld_safe Logging to ‘/var/log/mysqld.log‘.

150403 10:43:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

mysql -uroot    #可以这样输入,也可以直接输入mysql回车,因为安全模式是root权限的。

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> use mysql;    #切换到mysql数据库

Database changed

mysql> UPDATE user SET Password=PASSWORD(‘root‘) where USER=‘root‘;    #更新 root用户密码密码为root,这个根据自己改。

Query OK, 0 rows affected (0.01 sec)

Rows matched: 0  Changed: 0  Warnings: 0

mysql> FLUSH PRIVILEGES;    #强制刷新数据库记录。

Query OK, 0 rows affected (0.00 sec)

mysql> quit    #退出

Bye

到这里我相信很多朋友都会直接重启数据库,我之前也一样,问题一样存在。因为我们刚才是用安全模式启用过Mysql,在进程还会存在一个mysqld_safe Number of processes running now: 0    必须要把这个安全模式的进程结束后再重启mysql即可登陆。

[[email protected] ~]# killall -9 mysqld    #结束进程里残留的Mysql进程。

[[email protected] ~]# /usr/bin/mysqld_safe: line 158:  1634 Killed                  nohup /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --skip-grant-tables --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock < /dev/null >> /var/log/mysqld.log 2>&1

150403 10:46:47 mysqld_safe Number of processes running now: 0

150403 10:46:47 mysqld_safe mysqld restarted

[[email protected] ~]# service mysqld start

Starting mysqld:                                           [  OK  ]

[[email protected] ~]# mysql -uroot -p

输入刚才更改的密码即可进入数据库。

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

时间: 2024-11-05 23:19:33

ERROR 1045 (28000): Access denied for user 'root'@'localhost' 的解决方法的相关文章

ERROR 1045 (28000): Access denied for user &#39;ODBC&#39;@&#39;localhost&#39;的解决方法

[mysql]ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost'的解决方法 在安装完MySQL并添加环境变量之后 由于在MySQL安装过程中设置了密码,导致直接在cmd中登陆出现了上面问题, 解决方式: 正确的cmd登陆命令应该如下所示(红字部分):之后会提示输入密码 即可进入MySQL C:\users\Laoyu_>mysql -u root -p Enter password: ******(输入你的密码) (图见附件

Ubuntu下连接mysql出现 ERROR 1698 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39;错误解决方法

ubuntu版本:18.04    mysql版本:5.7.24 ubuntu安装mysql后用root账户登入会出现问题:ERROR 1698 (28000): Access denied for user 'root'@'localhost' 可能是因为初始密码为空:按空格回车后还是报一样的错 这样就只能使用debian-sys-maint账户修改root账户密码了. debian-sys-maint账户是安装mysql时系统自动生成的mysql用户,debian和ubuntu系统都会这样做

ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO)

在安装好的MySQL服务器上,配置了环境变量之后,发现用mysql无法登录,报如题的错误,实在没有办法,决定用安全模式对root用户修改密码: 首先在一个ssh窗口运行命令:mysqld_safe --user=mysql --skip-grant-tables --skip-networking& [[email protected] ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking& 运行之后新打开一个

Mac下解决mysql ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)

Maybe updating the package the updater overwrote the root password. To restore it: Stop mysqld deamons. $ sudo service mysqld stop Go to mysql/bin directory $ cd /usr/bin Start a mysql deamon with this option: $ sudo mysqld_safe --skip-grant-tables O

升级到macOS 10.12 mysqlb报错ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO)

系统升级到macOS 10.12后启动mysql后,在终端输入mysql 报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES/NO) 解决办法1 在系统偏好设置里关闭mySQL2 $ cd /usr/bin3 $ sudo mysqld_safe --skip-grant-tables4 再打开一个终端$ mysqlmysql> use mysql;mysql> UPDATE

MySQL使用错误解决:ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO)

解决方法: ⑴打开mysql中的my.ini(如果没有就将my-default.ini复制一份,并修改为my.ini): ⑵在[mysqld]下面空白行直接添加skip-grant-tables: ⑶重启mysql,在cmd页面输入mysql,按回车键即可. 注:这会使你的mysql无法设置密码,但对个人使用而言这岂不是更省了一步! MySQL使用错误解决:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using p

ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)

To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -

MySQL5.5出面ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)问题的解决办法

问题描述 安装完MySQL5.5数据库,使用Navicat Premium以及命令窗口连接数据库都报以下错误: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 解决办法 通常该错误是忘记密码导致的,所以我们需要修改密码,具体操作步骤如下: 1.打开D:\Program Files\MySQL\MySQL Server 5.5\my.ini,在[mysqld]下增加一行启动参数

mysql登陆提示ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO

今天安装zabbix,安装完成之后在最上面提示如下所示 检查日志如下显示 显示连接数据库失败,登录mysql给zabbix授权之后发现zabbix彻底起不来了 数据库也登陆不进去,提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 数据库拒绝了root登录,于是先跳过受权表访问,命令如下:mysqld_safe --user=mysql --skip-grant-tables -