use mysql 1044 42000_mysql错误ERROR 1044 (42000): Access denied for user

mysql错误ERROR 1044 (42000): Access denied for user

发布时间:2020-04-03 14:30:18

来源:51CTO

阅读:1572

作者:老肖的博客

mysql错误ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'MAC'解决办法MariaDB [(none)]> create database MAC;

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'MAC'

MariaDB [(none)]>

方法一:

1.关闭mysql

# service mysqld stop 【 备注centos7是systemctl stop mariadb】

2.屏蔽权限

# mysqld_safe --skip-grant-table

屏幕出现: Starting demo from .....

3.新开起一个终端输入

#mysql -uroot -pxxxxxx

MariaDB [(none)]> use mysql;

MariaDB [mysql]>

MariaDB [mysql]> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';     【备注:下一次会用newpassword密码登录数据库】

MariaDB [mysql]>  FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误

MariaDB [mysql]>  \q

----------------------------------------------------------------------------

我的实操测试

[root@nessus ~]# systemctl stop mysqld

Failed to stop mysqld.service: Unit mysqld.service not loaded.

[root@nessus ~]# systemctl stop mariadb

[root@nessus ~]#

[root@nessus ~]#

[root@nessus ~]# mysqld_safe --skip-grant-table

191030 11:11:24 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.

191030 11:11:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

新开起一个终端输入

[root@nessus ~]# mysql -uroot  【我的无密码】

MariaDB [(none)]> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [mysql]> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

Query OK, 4 rows affected (0.01 sec)

Rows matched: 4  Changed: 4  Warnings: 0

MariaDB [mysql]>

MariaDB [mysql]>

MariaDB [mysql]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> \q

Bye

[root@nessus ~]# mysql -uroot  【发现之前无密码无法登陆了】

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@nessus ~]#

[root@nessus ~]# mysql -uroot -pnewpassword   【得用newpassword密码登录数据库】

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 5

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

MariaDB [(none)]>

MariaDB [(none)]>

MariaDB [(none)]> create database MAC;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]>

MariaDB [(none)]>

MariaDB [(none)]>

MariaDB [(none)]>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值