MYSQL小白的FAQ系列—-1—-使用rpm包后的常见问题

联系:QQ(5163721)

标题:MYSQL小白的FAQ系列—-1—-使用rpm包后的常见问题

作者:Lunar©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]

###########################################################################
问题1:使用rpm包安装后,登录mysql报错 ERROR 2002 (HY000):
###########################################################################

[root@lunar ~]# mysql -h localhost -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@lunar ~]#

解决:
检查安装记录,里面记录着:

2014-08-03 15:53:45 4780 [Note] InnoDB: FTS optimize thread exiting.
2014-08-03 15:53:45 4780 [Note] InnoDB: Starting shutdown...
2014-08-03 15:53:47 4780 [Note] InnoDB: Shutdown completed; log sequence number 1625987

因此,知道了,安装完成后,服务是关闭的,于是启动服务就好了,O(∩_∩)O哈哈~:

[root@lunar mysql]# service mysql status
MySQL is not running[FAILED]
[root@lunar mysql]# service mysql start
Starting MySQL...........................[  OK  ]
[root@lunar mysql]# service mysql status
MySQL running (3636)[  OK  ]
[root@lunar mysql]# mysql -h localhost -uroot 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

这里看到,之前的 ERROR 2002 (HY000)不见了,多出来新的报错:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

###########################################################################
问题2:上面的ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
###########################################################################

这个问题,主要是mysql 5.6在linux下使用rpm包安装后,会自动生成一个root的口令(之前的版本是空口令),这一信息在安装时有显示:

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

也就是说,安装后,建议使用SET PASSWORD修改口令,并使用/usr/bin/mysql_secure_installation删除test数据库。
这是强烈推荐的步骤。
于是首先使用它自动生成的口令登陆试试看:

[root@lunar ~]# cat /root/.mysql_secret
# The random password set for the root user at Sun Aug  3 13:53:17 2014 (local time): SThC8zYvMFuPjqdM

[root@lunar ~]# 
[root@lunar mysql]# mysql -h localhost -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.21-enterprise-commercial-advanced

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> 

可以了。
当然,这里我没有尝试,直接启动到安全模式,然后修改root口令,感觉应该也可以的。

此条目发表在 FAQ 分类目录,贴了 , , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注