Linux 中的 mysql数据库,命令被拒绝的问题(ERROR 1044: Access denied for user ''@'localhost')

khler 2011-02-11 01:33:10
1、在命令模式下直接敲mysql可以进入mysql:
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.1.49-community-log MySQL Community Server (GPL)
。。。


2、创建数据库出错:
mysql> create database tmonitor;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'tmonitor'
mysql>

我明明是root登录的,为什么会是''@'localhost' ?

3、另外,我show一下数据库,却发现没有'mysql'库,咋回事?我记得mysql数据库中默认有个名叫‘mysql’的数据库,用来维护用户名、配置参数等信息的库啊:

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)

mysql>

4、如果是因为匿名登录,那我退出重新进入mysql吧:

mysql> exit
Bye
[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost ~]#

——访问被拒绝了。。。。。。

各位大牛,这是咋回事?
是不是因为没有‘mysql’数据库,导致根本不存在‘root’这个用户,从而导致认证失败的?

...全文
19743 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
khler 2012-09-06
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 的回复:]
以为结贴以后就没法回复了。不好意思。灌水了。
不过还有一个原因可能是远程登录,而默认主机是localhost,此时应该用:
mysql -h 目标机器名 -u root -p
来登录mysql
[/Quote]

对,我18楼的意思就是我远程开了SSH窗口查看的才导致那些不明不白的问题。
20楼的xtlove_ytt兄弟,你的问题跟我类似,在上面那些哥们的回复中找找原因吧。
量子人生 2012-08-31
  • 打赏
  • 举报
回复
以为结贴以后就没法回复了。不好意思。灌水了。
不过还有一个原因可能是远程登录,而默认主机是localhost,此时应该用:
mysql -h 目标机器名 -u root -p
来登录mysql
  • 打赏
  • 举报
回复
大哥,我的问题跟你的问题一样,报的错也一样,可是我按照你说的方式去做了,重新启动服务后,那两个表还是不在,而且在登录的时候也不需要密码,同样也建不了数据库,是什么问题呢?对这个Linux系统本来就 不熟悉,而且那两个表是在啥时候不见的都不知道,先前都还有,后来就没有了,晕……
khler 2011-03-01
  • 打赏
  • 举报
回复
半小时后结贴,有更多想法的同学继续补充...
khler 2011-03-01
  • 打赏
  • 举报
回复
'低胸'们,我回来结贴了,问题解决了,详述如下:
思路还是重置密码,方法也是如下所述:

/etc/init.d/mysql stop (service mysqld stop )
/usr/bin/mysqld_safe --skip-grant-tables
另外开个SSH连接
[root@localhost ~]# mysql
mysql>use mysql
mysql>update user set password=password("123456") where user="root";
mysql>flush privileges;
mysql>exit

pkill -KILL -t pts/0 可将pts为0的**用户(之前运行mysqld_safe的用户窗口)强制踢出
正常启动 MySQL:/etc/init.d/mysql start (service mysqld start)


问题出在最后一步:你pkill时,pts/X,其中的‘X’不一定是0,可能是1,也可能是2,也可能是。。。所以你kill pts/0 肯定就不对了。你可以用'ps aux | grep pts'查到你重置密码的SSH窗口。
其实吧,上面那是文明的粗鲁做法,最简单的是粗鲁的文明做法:直接把重置密码的SSH窗口关闭就行了,哈哈

chinanewboy 2011-02-13
  • 打赏
  • 举报
回复
第一用mysql构建环境的时候 也出现过 1044 的错误,后来是在启动mysql的时候加了一个参数就可以了。
sorry参数具体是什么记不太清了。你google下吧。。
aleng18 2011-02-13
  • 打赏
  • 举报
回复
看到数据目录 /var/lib/mysql 下面有mysql、test和tmonitor三个库,---------有tmonitor库!无需再建tmonitor库,也无法建。
但show出来只有只有test,不知道mysql和tmonitor哪儿去了?----root的权限被清空了,root成了匿名用户了。

很可能你装来装去,搞乱了。这时候,建议你备份tmonitor库后,停掉mysql库,把整个data目录删除,然后用mysql_install_db命令重新建。
mysql_install_db --basedir=/usr --datadir=/var/lib/mysql --user=mysql
其中basedir不一定是usr,自己研究下再确定,别搞错了。
--basedir The path to the MySQL installation directory.

备份恢复tmonitor库:
这个库所有表假如都是myisam,或没有innodb表的话,停库后复制走即备份,复制回即恢复。
有innodb表的话,需要备份所有innodb表空间,即ibdate*和ib_log*
khler 2011-02-12
  • 打赏
  • 举报
回复
好啊,希望多多关注!

之前用root登录mysql进不去,我用如下方法重置:

这种问题需要强行重新修改密码,方法如下:

/etc/init.d/mysql stop (service mysqld stop )
/usr/bin/mysqld_safe --skip-grant-tables
另外开个SSH连接
[root@localhost ~]# mysql
mysql>use mysql
mysql>update user set password=password("123456") where user="root";
mysql>flush privileges;
mysql>exit

pkill -KILL -t pts/0 可将pts为0的**用户(之前运行mysqld_safe的用户窗口)强制踢出
正常启动 MySQL:/etc/init.d/mysql start (service mysqld start)


然后在命令行直接敲mysql就能进去,敲 mysql -u root 也都能进去,但是创建数据库时都提示:

mysql> create database tmonitor
-> ;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'tmonitor'

用户不是root,还是空(匿名用户?)

我通过ps查看启动参数:

root 7947 0.0 0.0 68076 1312 pts/1 S 10:54 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid
mysql 8056 0.0 0.3 136180 14860 pts/1 Sl 10:54 0:00 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock --port=3306

看到数据目录 /var/lib/mysql 下面有mysql、test和tmonitor三个库,但show出来只有:

[root@localhost mysql]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.49-community-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)

mysql>

只有test,不知道mysql和tmonitor哪儿去了?
hawk198 2011-02-12
  • 打赏
  • 举报
回复
mysql数据库文件夹被删除了,或者被移动了,现在分区上找找看在哪里,看看时间对不对,如果是移动了,移回来即可,如果是删除了,那就要找一个相同的库覆盖或者重装了
aleng18 2011-02-12
  • 打赏
  • 举报
回复
Access denied for user ''@'localhost'----电脑告诉你,匿名用户在本机毫无权限的意思。
Access denied for user 'root'@'localhost' -------root密码不对。
你的root假如没有密码,那么mysql -u root 就能进去。
也就是mysql和tmonitor数据库都不见了--------可能是没权限查看。
综上所述,这是root密码忘记类问题。
解决方法见手册 A.4.1. 如何复位根用户密码

starshift 2011-02-11
  • 打赏
  • 举报
回复
去数据库路径下面检查一下文件权限。
steptodream 2011-02-11
  • 打赏
  • 举报
回复
肯定是你误删了!
freetstar 2011-02-11
  • 打赏
  • 举报
回复
不是误删了吧
关注此帖
khler 2011-02-11
  • 打赏
  • 举报
回复
我现在就想在里面create database tmonitor,然后把之前用mysqldump备份的*.sql文件导入,现在是“create database tmonitor”就出错了
khler 2011-02-11
  • 打赏
  • 举报
回复
额滴个神哪,终于有人回复了,还不少呢

我的数据库昨天之前其实跑的好好的,里面有个tmonitor的数据库。由于要另外装个服务,用到了mysql,而且自动做了一些更新,结果我的tmonitor应用程序用不了了,而且进入mysql时出现 justkk 提供的大贴的问题,也照着方法一修改了,结果进去后发现:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+

也就是mysql和tmonitor数据库都不见了,就是我上面贴子里描述的第3点
无知者无谓 2011-02-11
  • 打赏
  • 举报
回复
试试:
mysql -u root
steptodream 2011-02-11
  • 打赏
  • 举报
回复
你根本没说前因后果! 你安装之后 都还干了那些别的操作?

mysql默认安装之后root是没有密码的 会提示你设置root密码 你设置了吗?

如果你啥也不记得了 只有用楼上的连接里的恢复方法
freetstar 2011-02-11
  • 打赏
  • 举报
回复
应该是刚开始要初始化root的密码的
khler 2011-02-11
  • 打赏
  • 举报
回复
牛儿们都回家过年了还没回来吗?
咋没人解决呢???
加载更多回复(1)

19,613

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧