疑难杂症汇总

Redis

1、Redis未能持久化,错误message

Redis bug----(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able

解决方案:

[root@VM_58_118_centos controllers]# redis-cli
192.168.12.188:6379> config set stop-writes-on-bgsave-error no

 

Mysql

1、Mysql数据库报错:

SQLSTATE[HY000] [2002] No such file or directory

解决方案:

[root@VM_58_118_centos controllers]# cat /etc/my.cnf | grep socket=
socket=/var/lib/mysql/mysql.sock

[root@izbp18dv3a3metugyd02qxz ~]#  vim /etc/php.ini
pdo_mysql.default_socket= /var/lib/mysql/mysql.sock

[root@izbp18dv3a3metugyd02qxz ~]#systemctl restart httpd

 特别说明:

腾讯云主机php.ini并没有指定pdo_mysql.default_socket,也正常支持, 是因为php或pdo扩展在源码编译安装时候就--with-mysql-sock设置了,总结建议安装php前先安装好apache和mysql
[root@VM_58_118_centos syhuo.net]# cat /etc/php.ini |grep -i 'pdo_mysql.default_socket'
pdo_mysql.default_socket=

但phpinfo()发现pdo_mysql.default_socket=/var/lib/mysql/mysql.sock
[root@VM_58_118_centos syhuo.net]# php -r "phpinfo();"|grep -i 'pdo_mysql.default_socket'
pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock


php源码编译安装
./configure --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock
PDO_MYSQL扩展源码编译安装
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock
make
make install

php单机进程与mysql通信用unix_socket套接字,比tcp、ucp开销小,效率高,也不影响分布式式部署连接
$mysql_conf = array(
    'host'    => '47.96.29.133:3306',
    'db'      => 'mysql',
    'db_user' => 'root',
    'db_pwd'  => 'Telpo.syhuo2019!@#',
    );
$pdo = new PDO("mysql:host=" . $mysql_conf['host'] . ";dbname=" . $mysql_conf['db'], $mysql_conf['db_user'], $mysql_conf['db_pwd']);//创建一个pdo对象
$pdo->exec("set names 'utf8'");
$sql = "select * from user where User = ?";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(1, 'root', PDO::PARAM_STR);
$rs = $stmt->execute();
if ($rs) {
    // PDO::FETCH_ASSOC 关联数组形式
    // PDO::FETCH_NUM 数字索引数组形式
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        var_dump($row);
    }
}

$pdo = null;//关闭连接
?>


php源码安装编译参数特别说明:

--with-apxs2=/usr/bin/apxs                                 #先安装好apache
--with-openssl
--with-pear
--enable-phar
--with-config-file-scan-dir=/etc/php.d
--with-config-file-path=/etc
--with-mysql=mysqlnd #先安装好mysql
--with-mysqli=mysqlnd
--with-pdo-mysql=mysqlnd
--with-mysql-sock=/var/lib/mysql/mysql.sock
--enable-maintainer-zts #线程安装,如果是nts,则需要去掉

./configure --prefix=/usr/local/php --with-apxs2=/usr/bin/apxs --with-config-file-scan-dir=/etc/php.d --with-config-file-path=/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-tidy --enable-zip --enable-soap --with-gettext --with-xsl --with-pear --enable-phar --enable-opcache --enable-fileinfo --enable-wddx --enable-static --enable-sysvshm --enable-sysvmsg --enable-shared --enable-apc --enable-apc-mmap --enable-apu

 php利用unix_socket连接操作mysql

参考文档:https://www.cnblogs.com/siqi/p/3774871.html

dns示例
mysql:host=localhost;port=3307;dbname=testdb
mysql:unix_socket=/tmp/mysql.sock;dbname=testdb

获取pdo对象
$dsn = "mysql:host=127.0.0.1;port=3306;dbname=test";
$opts = array(PDO::ATTR_AUTOCOMMIT=>0, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::ATTR_AUTOCOMMIT=>0 #关闭自动提交, PDO::ATTR_TIMEOUT => 3 #设置超时时间);
$pdo = new PDO($dsn, 'root', '', $opts);
ee($pdo->getAttribute(PDO::ATTR_AUTOCOMMIT)); // setAttribute 可以设置属性
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);  #设置获取的方式 

 



你可能感兴趣的:(疑难杂症汇总)