Using MySQL Sockets in the WordPress wp-config.php

2013-05-29

有时候,为了安全起见,我们会禁用mysql的端口3306,那么禁用了端口,怎么设置Wordpress用mysql.sock连接mysql呢?

 

1、禁用mysql端口3306,设置/usr/local/mysql/my.cnf,添加

[mysqld]

skip-networking

重启mysql

/etc/init.d/mysql restart

netstat -ntlp检查端口,3306不见了。

2、 The first thing you need to do is determine the path to the MySQL socket. By inspecting my.cnf you would need to look for something that looks like:

socket      = /var/run/mysqld/mysqld.sock

3、 If you don't have access to look at my.cnf you can try to run the following MySQL query:

SHOW VARIABLES LIKE 'socket';

4、 Now crack open your wp-config.php file and set DB_HOST to ':/path/to/mysql.sock'. Take careful note of the ':' (colon) preceding the path. In my example the define for the DB_HOST looks like:

define('DB_HOST', ':/var/run/mysqld/mysqld.sock');

define('DB_HOST', 'localhost:/var/run/mysqld/mysqld.sock');

define('DB_HOST', '127.0.0.1:/var/run/mysqld/mysqld.sock');

分类:wordpress | 标签: |

相关日志

评论被关闭!