ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysq
今天在linux里安装mysql,运行时遇到这样的错误ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'上网查了下:这种情况大多数是因为你的mysql是使用rpm方式安装的,它会自动寻找 /var/lib/mysql/mysql.sock 这个文件,通过unix socket登录mysql。常见解决办法如下:1、创建/修改文件 /etc/my.cnf,至少增加/修改一行[mysql][client]socket = /tmp/mysql.sock#在这里写上你的mysql.sock的正确位置,通常不是在 /tmp/ 下就是在 /var/lib/mysql/ 下2、指定IP地址,使用tcp方式连接mysql,而不使用本地sock方式#mysql -h127.0.0.1 -uuser -ppassword3、为 mysql.sock 加个连接,比如说实际的mysql.sock在 /tmp/ 下,则#ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock即可================启动服务service mysql startservice mysql stopservice mysql restart================添加mysql用户方式一)/usr/local/mysql/bin/mysql -h127.0.0.1 -u root mysql>use mysql;mysql>insert into user(host,user,password) values('%','esun',password('ccmysqlesun'));//创建远程用户mysql>flush privileges;mysql>grant all on *.* to 'esun'@'%' identified by 'ccmysqlesun'; || grant all on *.* to 'esun'@'localhost' identified by 'esun';