Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’解决

启动mysql 报错:

 

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

 

1、先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.
另外看看是不是权限问题.

 

2、确定你的mysql.sock是不是在那个位置,
mysql -u 你的mysql用户名 -p -S /var/lib/mysql/mysql.sock

 

3、试试:service mysqld start

 

4、如果是权限问题,则先改变权限 #chown -R mysql:mysql /var/lib/mysql

 

[root@localhost ~]# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]
[root@localhost ~]# mysql -uroot -p

 

 

 

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
   原因是,/var/lib/mysql 的访问权限问题。

shell> chown -R mysql:mysql /var/lib/mysql

接着启动服务器

shell> /etc/init.d/mysql start

服务器正常启动后察看 /var/lib/mysql 自动生成mysql.sock文件。

但是我的问题仍然没有得到解决。

问题终于解决:
方法:    修改/etc/my.conf:
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/usr/local/mysql

 

If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:

 

[client]
socket=/var/lib/mysql/mysql.sock


发现依旧如此,运行/etc/init.d/mysql start报错:    Starting MySQLCouldn't find MySQL manager or server
是mysqld服务没启,运行/usr/local/mysql/bin/mysqld_safe &

 

----------------------------------------------------------------------

1、rpm安装
    以指定路径–prefix=/usr/local/mysql
    --data默认放在:/var/lib/mysql
    ---mysql默认安装在了:/usr/share/mysql中
   
2、可以使用ps -ef|grep mysql    
root     17659     1  0  2011 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid  
mysql    17719 17659  0  2011 ?        03:14:57 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
usr/bin/mysql 是指:mysql的运行路径
var/lib/mysql 是指:mysql数据库文件的存放路径
usr/lib/mysql 是指:mysql的安装路径
   
linux下卸载mysql方法

a. 查找已安装的myslq 版本:
#rpm  -qa | grep  mysql (注意大小写,如果mysql 不行就换MySQL)

显示:
[root@localhost ~]# rpm  -qa | grep  mysql
mysql-5.0.77-4.el5_4.2
mysql-server-5.0.77-4.el5_4.2
php-mysql-5.2.13-1.el5.art
复制代码
在屏幕上将显示已安装的mysql包名如:mysql-5.0.77-4.el5_4.2 ;
将搜索出的包名卸载:
#rpm -e  –nodeps mysql-5.0.77-4.el5_4.2  (nodeps表示强制删除)
提示
error: package –nodeps is not installed
error: package mysql-.0.77-4.e15_.2 is not installed

 

 

-----------------------------------------------------------------------------

最近在Linux上装了个MySQL数据库,可是远程连接MySQL时总是报出erro 2003: Can't connect to MySQL server on '211.87.***.***' (111),昨天查了好几个小时才找到解决方案,如下:

1.sudo gedit /etc/mysql.my.cnf

找到bind-address      =127.0.0.1

修改为bind-address   =0.0.0.0

2.sudo /etc/init.d/ mysql restart

在这种情况下如果再尝试远程连接,则会报出ERROR 1130 (HY000): Host '211.87.***.***'is not allowed to connect to this MySQL server提示信息,不能远程连接数据库。

在MySQL host上按如下命令操作

mysql -u root -ppassword    //进入mysql控制台

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';    //这个命令执行错误时可略过

mysql>flush privileges;

mysql>select host, user from user; //检查‘%’ 是否插入到数据库中

mysql>quit

 

3、其它

mysqladmin -u root password 123           //改密码  
 在/ety/my.cnf中加入skip-grant-tables        //跳过mysql访问控制

你可能感兴趣的:(Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’解决)