Mysql报错的解决'Can't connect to local MySQL server through socket '/tmp/mysql.sock'

刚开始编译安装Mysql的时候,都弄完了以后总是出错,很是郁闷,而且这个问题我在几个机器上都遇到过。今天查网络,终于弄明白是怎么回事了,原来是权限设置不对,虽然是所有者权限了,但是忘记设置所属组了。所以错在这里,望大家遇到童言的问题多检查检查,这么马虎,用了这么长时间才弄好,惭愧啊
        以下是操作记录,从make install 完成以后开始记录,同时后边跟着一个网友的文章,忘记出处了。先拿过来写了。
==================
[root@localhost mysql]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
[root@localhost mysql]# service mysqld restart 这里说明mysqld并没有启动,
MySQL manager or server PID file could not be found!       [FAILED]
Starting MySQL/etc/init.d/mysqld: line 159: kill: (18977) - No such process
                                                           [FAILED]
[root@localhost mysql]# cd bin
[root@localhost bin]# ./mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)        这里就说了不能通过/tmp/mysql.sock连接数据库。
[root@localhost bin]# cd /tmp    进去检查,看到有这个文件,所以看别的原因。
[root@localhost tmp]# ls
gconfd-root  mapping-root  mysql.sock  mysql-test-ports  mysql-test-ports.sem  scim-panel-socket:0-root  VMwareDnD  vmware-root  vmware.txt
[root@localhost tmp]# cd /usr/local/mysql/
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# chown -R root:mysql .      忽然想起来了没有设置权限呢,开始设置权限
[root@localhost mysql]# ll
total 36
drwxr-xr-x 2 root mysql 4096 Nov 28 21:51 bin
drwxr-xr-x 3 root mysql 4096 Nov 28 21:50 include
drwxr-xr-x 2 root mysql 4096 Nov 28 21:50 info
drwxr-xr-x 3 root mysql 4096 Nov 28 21:50 lib
drwxr-xr-x 2 root mysql 4096 Nov 28 21:51 libexec
drwxr-xr-x 4 root mysql 4096 Nov 28 21:50 man
drwxr-xr-x 8 root mysql 4096 Nov 28 21:51 mysql-test
drwxr-xr-x 3 root mysql 4096 Nov 28 21:50 share
drwxr-xr-x 5 root mysql 4096 Nov 28 21:50 sql-bench
[root@localhost mysql]# chown -R mysql /var/lib/mysql
[root@localhost mysql]# cp share/mysql/my-huge.cnf /etc/my.cnf
[root@localhost mysql]# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --level 345 mysqld on
=======error========
[root@localhost mysql]# mysqladmin -u root password 'uplooking'
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!  又是上边一样的错误
[root@localhost mysql]# bin/mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
[root@localhost mysql]# /etc/rc.d/init.d/mysqld status
MySQL is not running, but lock exists                      [FAILED] 这里说的是没有运行着mysql,但是还在锁定。这时候我看到了下边那篇文章,重新检查了一遍权限,
[root@localhost mysql]# chown -R mysql:mysql /var/lib/mysql 在这里,我原来设置的时候这个组没有设置,只写了chown -R mysql /var/lib/mysql,分组被我忽略掉了,哎,折腾这么长时间。
[root@localhost mysql]# /etc/rc.d/init.d/mysqld start 从这里,mysql启动正常了
Starting MySQL                                             [  OK  ]
[root@localhost mysql]# /etc/rc.d/init.d/mysqld stop
Shutting down MySQL                                        [  OK  ]
[root@localhost mysql]#
[root@localhost mysql]# mysqladmin -u root password 'uplooking' 这里是说服务器没有启动
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
[root@localhost mysql]# /etc/rc.d/init.d/mysqld start 启动服务器
Starting MySQL                                             [  OK  ]
[root@localhost mysql]# mysqladmin -u root password 'uplooking' 添加root密码
[root@localhost mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost mysql]# mysql -u root -p 用root密码登陆,测试。
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.56-Comsenz-log Source

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

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

mysql> quit
Bye
[root@localhost mysql]# service mysqld restart
Shutting down MySQL                                        [  OK  ]
Starting MySQL                                             [  OK  ]
[root@localhost mysql]#

====权限的验证测试====
[root@localhost mysql]# cd /tmp
[root@localhost tmp]# mkdir test
[root@localhost tmp]# cd test
[root@localhost test]# ls
[root@localhost test]# touch 11
[root@localhost test]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 28 22:37 11
[root@localhost test]# chown -R mysql 11
[root@localhost test]# ll
total 0
-rw-r--r-- 1 mysql root 0 Nov 28 22:37 11
[root@localhost test]#
=========================
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值