我的mysql无法连接的问题

回复 收藏
我按照铭哥教程安装的mysql,现在在学习discuz的时候发现mysql有问题,无法连接了。
[root@jdzlinux ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

我也没有设置密码,这个该如何处理啊?
谢谢。
2016-05-11 09:50 举报
已邀请:
0

乐橙306

赞同来自:

你试试通过重置mysql  root 密码来解决
http://www.apelearn.com/bbs/fo ... 3D252

链接和你的问题差不多  你看看吧

http://forums.mysql.com/read.php?11,34014,163619#msg-163619

http://www.apelearn.com/bbs/thread-12618-1-1.html





0

664778717@qq.co

赞同来自:

账号密码不对吧
0

liulangren0533

赞同来自:

乐橙306 发表于 2016-5-11 10:21
你试试通过重置mysql  root 密码来解决
http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=252
...

谢谢,不过我的mysql里面user表是空的。
mysql> select * from user;
Empty set (0.00 sec)

update也不生效。
mysql> update user set password=password('123456') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

这个改如何处理呢?
谢谢。
0

liulangren0533

赞同来自:

乐橙306 发表于 2016-5-11 10:21
你试试通过重置mysql  root 密码来解决
http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=252
...

谢谢,不过我的mysql里面user表是空的。
mysql> select * from user;
Empty set (0.00 sec)

update也不生效。
mysql> update user set password=password('123456') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

这个改如何处理呢?
谢谢。
0

liulangren0533

赞同来自:

乐橙306 发表于 2016-5-11 10:21
你试试通过重置mysql  root 密码来解决
http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=252
...

谢谢,不过我的mysql里面user表是空的。
mysql> select * from user;
Empty set (0.00 sec)

update也不生效。
mysql> update user set password=password('123456') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

这个改如何处理呢?
谢谢。
0

liulangren0533

赞同来自:

乐橙306 发表于 2016-5-11 10:21
你试试通过重置mysql  root 密码来解决
http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=252
...

谢谢,不过我的mysql里面user表是空的。
mysql> select * from user;
Empty set (0.00 sec)

update也不生效。
mysql> update user set password=password('123456') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

这个改如何处理呢?
谢谢。
0

liulangren0533

赞同来自:

咋搞的,回复这么多??
0

liulangren0533

赞同来自:


我没有设置密码。
我现在进入mysql查看user表内容也是空的。
0

乐橙306

赞同来自:

liulangren0533 发表于 2016-5-11 10:45
咋搞的,回复这么多??

重新操作一遍  并把过程截图  贴出来
0

liulangren0533

赞同来自:

乐橙306 发表于 2016-5-11 10:58
重新操作一遍  并把过程截图  贴出来

[root@jdzlinux ~]# service mysqld stop
Shutting down MySQL. SUCCESS!
[root@jdzlinux ~]# vim /etc/my.cnf
增加 skip-grant-tables
[root@jdzlinux ~]# service mysqld start
Starting MySQL. SUCCESS!
[root@jdzlinux ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73-log MySQL Community Server (GPL)

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>
mysql> use mysql;
Database changed
mysql> update user set password=password('123456') where user='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>

mysql> quit
Bye
[root@jdzlinux ~]# vim /etc/my.cnf
删除 skip-grant-tables
[root@jdzlinux ~]# service mysqld restart
Shutting down MySQL... SUCCESS!
Starting MySQL. SUCCESS!
[root@jdzlinux ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@jdzlinux ~]#
0

tytywu

赞同来自:

liulangren0533 发表于 2016-5-11 10:43
谢谢,不过我的mysql里面user表是空的。
mysql> select * from user;
Empty set (0.00 sec)

初次设置密码不是在mysql中设置的,我当时测试的时候也是这样,[root@localhost ~]# mysqladmin -uroot password 'yourpassword' !这里需要注意一下!
0

liulangren0533

赞同来自:

tytywu 发表于 2016-5-11 11:11
初次设置密码不是在mysql中设置的,我当时测试的时候也是这样,[root@localhost ~]# mysqladmin -uroot p ...

现在是无法连接到数据库,执行命令也不成功。
[root@jdzlinux ~]# mysqladmin -uroot password '123456'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
[root@jdzlinux ~]#
0

乐橙306

赞同来自:

liulangren0533 发表于 2016-5-11 11:10
[root@jdzlinux ~]# service mysqld stop
Shutting down MySQL. SUCCESS!
[root@jdzlinux ~]# vim /etc ...


看图片
0

liulangren0533

赞同来自:


[root@jdzlinux ~]# mysql -uroot -p123456
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@jdzlinux ~]#
0

乐橙306

赞同来自:

liulangren0533 发表于 2016-5-11 11:29
[root@jdzlinux ~]# mysql -uroot -p123456
ERROR 1045 (28000): Access denied for user 'root'@'local ...

你看下 二楼的链接吧     在里面找找解决方法
0

liulangren0533

赞同来自:

乐橙306 发表于 2016-5-11 11:33
你看下 二楼的链接吧     在里面找找解决方法

非常感谢您的回复。
0

liulangren0533

赞同来自:

问题终于解决啦!
先执行  mv  /data/mysql/mysql  /data/mysql/mysql.1
然后mysql重新初始化一下。
[root@localhost src]# cd /usr/local/mysql
[root@localhost mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
最重要的一点:初始化以后要重启mysqld服务。
至此问题解决!
谢谢 七期-孙冬学长热心的回帖指导。
感谢铭哥的指导!{:7_180:}

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: