phpmyadmin与php.ini中的socket配置问题

昨天在安装完新的perconesql数据后,发现phpmyadmin不能正常连接了。一时查来查去不知出了什么问题。

后来经过确认,由于php.ini中的mysqli.default_socket和pdo_mysql.default_socke默认为空,实际默认即为/tmp/mysql.sock,此时如果和mysql本身的设置不一致,就会导致phpmyadmin无法有效登录。

我们先查询mysql服务器使用的socket位置:

# mysql -u root -p
Enter password: yourpasswd
mysql> STATUS;
--------------
mysql  Ver 14.14 Distrib 5.7.21-21, for Linux (x86_64) using  6.2

Connection id:		2
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.21-21 Percona Server (GPL), Release 21, Revision 2a37e4e
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8
Db     characterset:	utf8
Client characterset:	utf8
Conn.  characterset:	utf8
UNIX socket:		/var/lib/mysql/mysql.sock
Uptime:			26 min 14 sec

Threads: 1  Questions: 5  Slow queries: 0  Opens: 105  Flush tables: 1  Open tables: 98  Queries per second avg: 0.003
--------------

mysql> exit
Bye

上面命令中查询到的socket地址为/var/lib/mysql/mysql.sock

修改php.ini文件中的两项:

vi  /etc/php.ini


mysqli.default_socket = /var/lib/mysql/mysql.sock 



pdo_mysql.default_socket = /var/lib/mysql/mysql.so

你也可以设置mysql配置文件my.cnf

vi /etc/my.cnf

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

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

至此,重启php或httpd就可以登录phpmyadmin

留下评论

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