我正在Centos7
和Mysql 5.6.46
. 我需要将默认 datadir 位置移动到加密分区,并相应地更改了我的默认 /etc/my.cnf 文件:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/NEW_FOLDER/mysql
socket=/NEW_FOLDER/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql_mode=""
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
port=3306
socket=/NEW_FOLDER/mysql/mysql.sock
重新启动后,我验证我可以通过编写连接到 Mysql: mysql -u <USERNAME> -p
,没有问题。当我的基于 CGI 的服务器尝试访问数据库时,我的问题与此有关。我收到错误:Error connecting to database: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
这对我来说没有多大意义,因为默认套接字目录已更改。
我查看了 Apache 错误日志,我看到了这个:
DBI connect('testuser:localhost','testdb',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at /srv/www/TestSite/perl-lib/Database.pm line 31.
我转到第 31 行,我看到了这个:
my $dsn = "DBI:mysql:testdb:localhost";
$dbh = DBI->connect($dsn, 'testuser', 'testpasswd')
or throw Portal::DatabaseError("Error connecting to database: $DBI::errstr");
在我看来,Apache 正在尝试访问 Mysql,但它不能mysql.socket
从新的默认mysql datadir
位置使用。有什么想法该怎么做?