今天连接mysql数据库的时候遇到一个问题:Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
参考网上相关的方法,包括:(http://blog.youkuaiyun.com/lmss82/archive/2009/08/05/4414178.aspx)
方案1.
1.#ps -A|grep mysql
显示类似:
1829 ? 00:00:00 mysqld_safe
1876 ? 00:00:31 mysqld
2.#kill -9 1829
3.#kill -9 1876
4.#/etc/init.d/mysql restart
5.#mysql -u root -p
他的麻烦解决了,我的还没解决!
继续找
方案2
先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.
另外看看是不是权限问题.
------------------------------------------------------------------------------------
[root@localhost beinan]#chown -R mysql:mysql /var/lib/mysql
[root@localhost beinan]# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]
[root@localhost lib]# mysqladmin -uroot password '123456'
[root@localhost lib]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 3 to server version: 4.1.11
Type 'help;' or '/h' for help. Type '/c' to clear the buffe
他的也解决了,我的麻烦还在继续,依然继续寻找
方案3
问题解决了,竟然是max_connections=1000 他说太多了,然后改成500也说多,无奈删之问题解决了。
还是不行
方案4
/var/lib/mysql 所有文件权限 改成mysql.mysql
不行不行
方案5
摘要:解决不能通过mysql .sock连接MySQL问题 这个问题主要提示是,不能通过 '/tmp/mysql .sock'连到服务器,而php标准配置正是用过'/tmp/mysql .sock',但是一些mysql 安装方法 将 mysql .sock放在/var/lib/mysql .sock或者其他的什么地方,你可以通过修改/etc/my.cnf文件来修正它,打开文件,可以看到如下的东东:
[mysql d]
socket=/var/lib/mysql .sock
改一下就好了,但也会引起其他的问题,如mysql 程序连不上了,再加一点:
[mysql ]
socket=/tmp/mysql .sock
或者还可以通过修改php.ini中的配置来使php用其他的mysql .sock来连,这个大家自己去找找
或者用这样的方法:
ln -s /var/lib/mysql /mysql .sock /tmp/mysql .sock
成功了,就是这样ln -s /var/lib/mysql /mysql .sock /tmp/mysql .sock
OK!
但我的系统中没有找到mysql.sock文件,只有mysqld.sock文件,/var/run/mysqld/mysqld.sock
于是仿照上面的做法: ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
这样,可以正常连接数据库了
再附一篇相关文章:(http://blog.chinaunix.net/u1/43706/showart_351145.html)
mysql_real_connect()试图建立到运行host
的一个MySQL数据库引擎的一个连接。其函数原形为:
MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned int client_flag)
启动MYSQL是出现以下错误:
[root@www ~]# /usr/local/webserver/mysql/bin/mysqladmin -u root -p 12345678
Enter password:
/usr/local/webserver/mysql/bin/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@www ~]# /usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.38-log Source distributionType ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
mysql的参数说明:
/usr/local/webserver/mysql/bin/mysql –help | less
列举常用参数:
-u, –user=name User for login if not current user.
-p, –password[=name]
Password to use when connecting to server. If password is
not given it’s asked from the tty.
-S, –socket=name Socket file to use for connection.
it’s ok !
今天连接mysql数据库的时候遇到一个问题:Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
参考网上相关的方法,包括:(http://blog.youkuaiyun.com/lmss82/archive/2009/08/05/4414178.aspx)
方案1.
1.#ps -A|grep mysql
显示类似:
1829 ? 00:00:00 mysqld_safe
1876 ? 00:00:31 mysqld
2.#kill -9 1829
3.#kill -9 1876
4.#/etc/init.d/mysql restart
5.#mysql -u root -p
他的麻烦解决了,我的还没解决!
继续找
方案2
先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.
另外看看是不是权限问题.
------------------------------------------------------------------------------------
[root@localhost beinan]#chown -R mysql:mysql /var/lib/mysql
[root@localhost beinan]# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]
[root@localhost lib]# mysqladmin -uroot password '123456'
[root@localhost lib]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 3 to server version: 4.1.11
Type 'help;' or '/h' for help. Type '/c' to clear the buffe
他的也解决了,我的麻烦还在继续,依然继续寻找
方案3
问题解决了,竟然是max_connections=1000 他说太多了,然后改成500也说多,无奈删之问题解决了。
还是不行
方案4
/var/lib/mysql 所有文件权限 改成mysql.mysql
不行不行
方案5
摘要:解决不能通过mysql .sock连接MySQL问题 这个问题主要提示是,不能通过 '/tmp/mysql .sock'连到服务器,而php标准配置正是用过'/tmp/mysql .sock',但是一些mysql 安装方法 将 mysql .sock放在/var/lib/mysql .sock或者其他的什么地方,你可以通过修改/etc/my.cnf文件来修正它,打开文件,可以看到如下的东东:
[mysql d]
socket=/var/lib/mysql .sock
改一下就好了,但也会引起其他的问题,如mysql 程序连不上了,再加一点:
[mysql ]
socket=/tmp/mysql .sock
或者还可以通过修改php.ini中的配置来使php用其他的mysql .sock来连,这个大家自己去找找
或者用这样的方法:
ln -s /var/lib/mysql /mysql .sock /tmp/mysql .sock
成功了,就是这样ln -s /var/lib/mysql /mysql .sock /tmp/mysql .sock
OK!
但我的系统中没有找到mysql.sock文件,只有mysqld.sock文件,/var/run/mysqld/mysqld.sock
于是仿照上面的做法: ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
这样,可以正常连接数据库了
再附一篇相关文章:(http://blog.chinaunix.net/u1/43706/showart_351145.html)
mysql_real_connect()试图建立到运行host
的一个MySQL数据库引擎的一个连接。其函数原形为:
MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned int client_flag)
启动MYSQL是出现以下错误:
[root@www ~]# /usr/local/webserver/mysql/bin/mysqladmin -u root -p 12345678
Enter password:
/usr/local/webserver/mysql/bin/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@www ~]# /usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.38-log Source distributionType ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
mysql的参数说明:
/usr/local/webserver/mysql/bin/mysql –help | less
列举常用参数:
-u, –user=name User for login if not current user.
-p, –password[=name]
Password to use when connecting to server. If password is
not given it’s asked from the tty.
-S, –socket=name Socket file to use for connection.
it’s ok !