1

Topic: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

==== Required information ====
- iRedMail version (check /etc/iredmail-release): 0.9.2
- Linux/BSD distribution name and version: FreeBSD 10.2
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Apache
- Manage mail accounts with iRedAdmin-Pro? No
- Related log if you're reporting an issue:
====

Hi,

I have had this same problem yesterday while installing a fresh copy in a fresh FreeBSD 10.2 installation, I have followed a previous topic by 3m and changed the MySQL files as suggested but the problem continues. Have you had the scripts change since then? Do I have to reinstall the whole system from scratch in order to apply these changes? or can I just run the bash iRedadmin.sh script again?

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

I'm afraid that you have to reinstall the whole system from scratch.

Did you install in a jailed FreeBSD?

3

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

Hi,

I have now done the changes in a newly installed FreeBSD 10.2 and reinstalled everything but I got same problem. What do you mean by a jailed FreeBSD?

4

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

This is the install log:

[ INFO ] Create required system account: vmail, iredadmin, iredapd.
+ < DEBUG > Create HOME folder for vmail user.
+ < DEBUG > Create system account: vmail:vmail (2000:2000).
rm: "." and ".." may not be removed
+ < DEBUG > Create directory to store user sieve rule files: /usr/vmail/sieve.
+ < DEBUG > Create system account: iredadmin:iredadmin (2001:2001)
+ < DEBUG > Create system account: iredapd:iredapd (2002:2002).
[ INFO ] Configure Apache web server and PHP.
+ < DEBUG > Basic configurations.
+ < DEBUG > Set correct SSL Cert/Key file location.
+ < DEBUG > Enable Apache modules.
+ < DEBUG > Configure Apache.
accf_http_load="YES"
+ < DEBUG > Add setting in /etc/rc.conf: apache24_enable='YES'
+ < DEBUG > Add setting in /etc/rc.conf: htcacheclean_enable='NO'
[ INFO ] Configure PHP.
+ < DEBUG > Hide PHP Version in Apache from remote users requests: /usr/local/etc/php.ini.
+ < DEBUG > Increase 'memory_limit' to 256M: /usr/local/etc/php.ini.
+ < DEBUG > Increase 'upload_max_filesize', 'post_max_size' to 10/12M: /usr/local/etc/php.ini.
+ < DEBUG > Disable php extension: suhosin. /usr/local/etc/php.ini.
[ INFO ] Configure MySQL database server.
+ < DEBUG > Generate temporary defauts file for MySQL client option --defaults-file: /usr/home/godinho/iRedMail-0.9.2/.mysql-root-defaults-file.
+ < DEBUG > Starting MySQL.
+ < DEBUG > Add setting in /etc/rc.conf: mysql_enable='YES'
+ < DEBUG > Add setting in /etc/rc.conf: mysql_optfile='/usr/local/etc/my.cnf'
+ < DEBUG > Copy sample MySQL config file: /usr/home/godinho/iRedMail-0.9.2/samples/mysql/my.cnf -> /usr/local/etc/my.cnf.
innodb_file_per_table
mysql not running? (check /var/db/mysql/mail.verdeazul.co.mz.pid).
+ < DEBUG > Sleep 5 seconds for MySQL daemon initialization ...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
+ < DEBUG > Initialize MySQL database.
+ < DEBUG > Generating SQL template for postfix virtual hosts: /usr/home/godinho/iRedMail-0.9.2/runtime/mysql_vmail.sql.
+ < DEBUG > Import postfix virtual hosts/users: /usr/home/godinho/iRedMail-0.9.2/runtime/mysql_vmail.sql.
[ INFO ] Setup daily cron job to backup SQL databases: /usr/vmail/backup/backup_mysql.sh
[ INFO ] Configure Postfix (Message Transfer Agent).
+ < DEBUG > Enable chroot.
+ < DEBUG > Copy: /etc/{hosts,resolv.conf,localtime,services} -> /var/spool/postfix/etc/
+ < DEBUG > Add setting in /etc/rc.conf: postfix_enable='YES'
+ < DEBUG > Add setting in /etc/rc.conf: sendmail_enable='NO'
+ < DEBUG > Add setting in /etc/rc.conf: sendmail_submit_enable='NO'
+ < DEBUG > Add setting in /etc/rc.conf: sendmail_outbound_enable='NO'
+ < DEBUG > Add setting in /etc/rc.conf: sendmail_msp_queue_enable='NO'
+ < DEBUG > Add setting in /etc/rc.conf: daily_clean_hoststat_enable='NO'
+ < DEBUG > Add setting in /etc/rc.conf: daily_status_mail_rejects_enable='NO'
+ < DEBUG > Add setting in /etc/rc.conf: daily_status_include_submit_mailq='NO'
+ < DEBUG > Add setting in /etc/rc.conf: daily_submit_queuerun='NO'
+ < DEBUG > Configure Postfix for MySQL lookup.
+ < DEBUG > Set file permission: Owner/Group -> postfix/postfix, Mode -> 0640.
+ < DEBUG > Configure SMTP SASL authentication.
+ < DEBUG > Enable TLS/SSL support in Postfix.
[ INFO ] Configure Cluebringer (postfix policy server).
+ < DEBUG > Add user and group for Cluebringer: policyd:policyd.
+ < DEBUG > Initialize SQL database for policyd.
+ < DEBUG > Add setting in /etc/rc.conf: policyd2_enable='YES'
+ < DEBUG > Configure webui of Policyd (cluebringer).
+ < DEBUG > Setup user auth for cluebringer webui: /usr/local/etc/apache24/Includes/cluebringer.conf.
[ INFO ] Configure Dovecot (pop3/imap/managesieve server).
+ < DEBUG > Configure dovecot: /usr/local/etc/dovecot/dovecot.conf.
+ < DEBUG > Copy global sieve filter rule file: /usr/vmail/sieve/dovecot.sieve.
+ < DEBUG > Create dovecot log file: /var/log/dovecot.log.
+ < DEBUG > Create dovecot log file: /var/log/dovecot-sieve.log.
+ < DEBUG > Create dovecot log file: /var/log/dovecot-lmtp.log.
+ < DEBUG > Enable dovecot SASL support in postfix: /usr/local/etc/postfix/main.cf.
+ < DEBUG > Create directory for Dovecot plugin: Expire.
+ < DEBUG > Setting logrotate for dovecot log file.
+ < DEBUG > Add setting in /etc/rc.conf: dovecot_enable='YES'
[ INFO ] Configure ClamAV (anti-virus toolkit).
+ < DEBUG > Configure ClamAV: /usr/local/etc/clamd.conf.
+ < DEBUG > Configure freshclam: /usr/local/etc/freshclam.conf.
+ < DEBUG > Add clamav user to amavid group.
+ < DEBUG > Add setting in /etc/rc.conf: clamav_clamd_enable='YES'
+ < DEBUG > Add setting in /etc/rc.conf: clamav_freshclam_enable='YES'
[ INFO ] Configure Amavisd-new (interface between MTA and content checkers).
+ < DEBUG > Configure amavisd-new: /usr/local/etc/amavisd.conf.
+ < DEBUG > Generate DKIM pem files: /var/lib/dkim/verdeazul.co.mz.pem.
+ < DEBUG > Setting cron job for vmail user to delete virus mail per month.
+ < DEBUG > Import Amavisd database and privileges.
+ < DEBUG > Add setting in /etc/rc.conf: amavisd_enable='YES'
+ < DEBUG > Add setting in /etc/rc.conf: amavisd_pidfile='/var/amavis/amavisd.pid'
+ < DEBUG > Add setting in /etc/rc.conf: amavis_milter_enable='NO'
+ < DEBUG > Add setting in /etc/rc.conf: amavis_p0fanalyzer_enable='NO'
[ INFO ] Configure SpamAssassin (content-based spam filter).
+ < DEBUG > Copy sample SpamAssassin config file: /usr/home/godinho/iRedMail-0.9.2/samples/spamassassin/local.cf -> /usr/local/etc/mail/spamassassin/local.cf.
+ < DEBUG > Enable crontabs for SpamAssassin update.
+ < DEBUG > Compile SpamAssassin ruleset into native code.
Oct 13 21:03:14.602 [30826] info: config: failed to parse line, skipping, in "/usr/local/etc/mail/spamassassin/local.cf": spf_timeout 5
Oct 13 21:03:14.829 [30826] info: generic: base extraction starting. this can take a while...
sa-compile: not compiling; 'spamassassin --lint' check failed!
[ INFO ] Configure iRedAPD (postfix policy daemon).
+ < DEBUG > Extracting: iRedAPD-1.6.0.tar.bz2 -> /opt
+ < DEBUG > Configure iRedAPD.
+ < DEBUG > Make iredapd start after system startup.
+ < DEBUG > Add setting in /etc/rc.conf: iredapd_enable='YES'
[ INFO ] Configure iRedAdmin (official web-based admin panel).
+ < DEBUG > Extracting: iRedAdmin-0.4.2.tar.bz2 -> /usr/local/www
+ < DEBUG > Set correct permission for iRedAdmin: /usr/local/www/iRedAdmin-0.4.2.
+ < DEBUG > Create directory alias for iRedAdmin.
+ < DEBUG > Import iredadmin database template.
+ < DEBUG > Configure iRedAdmin.
+ < DEBUG > Configure general settings.
+ < DEBUG > Configure iredadmin database related settings.
+ < DEBUG > Configure SQL mail accounts related settings.
+ < DEBUG > Configure Cluebringer related settings.
+ < DEBUG > Configure Amavisd related settings.
[ INFO ] Configure Roundcube webmail.
+ < DEBUG > Create directory alias for Roundcubemail.
+ < DEBUG > Import SQL database and privileges for Roundcubemail.
+ < DEBUG > Configure database for Roundcubemail: /usr/local/www/roundcube/config/*.
+ < DEBUG > Config plugin: managesieve.
+ < DEBUG > Enable and config plugin: password.
[ INFO ] Configure Awstats (logfile analyzer for mail and web server).
+ < DEBUG > Generate apache config file for awstats: /usr/local/etc/apache24/Includes/awstats.conf.
+ < DEBUG > Setup user auth for awstats: /usr/local/etc/apache24/Includes/awstats.conf.
+ < DEBUG > Config awstats to analyze apache web access log: /usr/local/www/awstats/cgi-bin/awstats.web.conf.
+ < DEBUG > Config awstats to analyze postfix mail log: /usr/local/www/awstats/cgi-bin/awstats.smtp.conf.
+ < DEBUG > Setting cronjob for awstats.
+ < DEBUG > Mail sensitive administration info to .
+ < DEBUG > Set file permission to 0600: /var/cron/tabs/root.
+ < DEBUG > Set file permission to 0600: /var/cron/tabs/vscan.
[ INFO ] Updating SpamAssassin rules (sa-update), please wait ...
error: no mirror data available for channel updates.spamassassin.org
channel: MIRRORED.BY file contents were missing, channel failed
[ INFO ] Compiling SpamAssassin rulesets (sa-compile), please wait ...
Oct 13 21:03:36.984 [31071] info: config: failed to parse line, skipping, in "/usr/local/etc/mail/spamassassin/local.cf": spf_timeout 5
Oct 13 21:03:37.003 [31071] info: generic: base extraction starting. this can take a while...
sa-compile: not compiling; 'spamassassin --lint' check failed!
[ INFO ] Updating ClamAV database (freshclam), please wait ...

5

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

Could you please show me full content in file 'functions/mysql.sh'?

6

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

#!/usr/bin/env bash

# Author:   Zhang Huangbin (zhb _at_ iredmail.org)

#---------------------------------------------------------------------
# This file is part of iRedMail, which is an open source mail server
# solution for Red Hat(R) Enterprise Linux, CentOS, Debian and Ubuntu.
#
# iRedMail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iRedMail is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iRedMail.  If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------

# Please refer another file: functions/backend.sh

# -------------------------------------------------------
# -------------------- MySQL ----------------------------
# -------------------------------------------------------
mysql_generate_defauts_file_root()
{
    if [ X"${BACKEND_ORIG}" == X'MARIADB' ]; then
        ECHO_INFO "Configure MariaDB database server."
    else
        ECHO_INFO "Configure MySQL database server."
    fi

    ECHO_DEBUG "Generate temporary defauts file for MySQL client option --defaults-file: ${MYSQL_DEFAULTS_FILE_ROOT}."
    cat >> ${MYSQL_DEFAULTS_FILE_ROOT} <<EOF
[client]
user=${MYSQL_ROOT_USER}
password="${MYSQL_ROOT_PASSWD}"
EOF

    if [ X"${LOCAL_ADDRESS}" != X'127.0.0.1' -o X"${MYSQL_SERVER}" != X'127.0.0.1' ]; then
        cat >> ${MYSQL_DEFAULTS_FILE_ROOT} <<EOF
host=${MYSQL_SERVER}
port=${MYSQL_SERVER_PORT}
EOF
    fi
}

mysql_initialize()
{
    ECHO_DEBUG "Starting MySQL."

    backup_file ${MYSQL_MY_CNF}

    # Initial MySQL database first
    if [ X"${DISTRO}" == X'OPENBSD' ]; then
        perl -pi -e 's#^(\[mysqld\])#${1}\nbind-address = 127.0.0.1#' ${MYSQL_MY_CNF}
        /usr/local/bin/mysql_install_db >> ${INSTALL_LOG} 2>&1
    elif [ X"${DISTRO}" == X'FREEBSD' ]; then
        # Start service when system start up.
        # 'mysql_enable=YES' is required to start service immediately.
        service_control enable 'mysql_enable' 'YES'
        service_control enable 'mysql_optfile' "${MYSQL_MY_CNF}"
    fi

    if [ ! -f ${MYSQL_MY_CNF} ]; then
        ECHO_DEBUG "Copy sample MySQL config file: ${SAMPLE_DIR}/mysql/my.cnf -> ${MYSQL_MY_CNF}."
        cp ${SAMPLE_DIR}/mysql/my.cnf ${MYSQL_MY_CNF} >> ${INSTALL_LOG} 2>&1
    fi

    # Disable 'skip-networking' in my.cnf.
    perl -pi -e 's#^(skip-networking.*)#${1}#' ${MYSQL_MY_CNF} >> ${INSTALL_LOG} 2>&1

    # Enable innodb_file_per_table by default.
    grep '^innodb_file_per_table' ${MYSQL_MY_CNF} >> ${INSTALL_LOG} 2>&1
    if [ X"$?" != X'0' ]; then
        perl -pi -e 's#^(\[mysqld\])#${1}\ninnodb_file_per_table#' ${MYSQL_MY_CNF} >> ${INSTALL_LOG} 2>&1
    fi

    service_control restart ${MYSQL_RC_SCRIPT_NAME} >> ${INSTALL_LOG} 2>&1

    ECHO_DEBUG "Sleep 5 seconds for MySQL daemon initialization ..."
    sleep 5

    if [ X"${LOCAL_ADDRESS}" == X'127.0.0.1' ]; then
        # Try to access without password, set a password if it's empty.
        mysql -u${MYSQL_ROOT_USER} -e "show databases" >> ${INSTALL_LOG} 2>&1
        if [ X"$?" == X'0' ]; then
            ECHO_DEBUG "Setting password for MySQL admin (${MYSQL_ROOT_USER})."
            mysqladmin --user=root password "${MYSQL_ROOT_PASSWD}"
        fi
    else
        ECHO_DEBUG "Grant access privilege to ${MYSQL_ROOT_USER}@${LOCAL_ADDRESS} ..."
        mysql -u${MYSQL_ROOT_USER} <<EOF
USE mysql;
-- Allow access from MYSQL_GRANT_HOST with password
GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_ROOT_USER}'@'${MYSQL_GRANT_HOST}' IDENTIFIED BY '${MYSQL_ROOT_PASSWD}';
GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_ROOT_USER}'@'127.0.0.1' IDENTIFIED BY '${MYSQL_ROOT_PASSWD}';
-- Allow GRANT privilege
UPDATE user SET Grant_priv='Y' WHERE User='${MYSQL_ROOT_USER}' AND Host='${MYSQL_GRANT_HOST}';
UPDATE user SET Grant_priv='Y' WHERE User='${MYSQL_ROOT_USER}' AND Host='127.0.0.1';
-- Set root password
UPDATE user SET Password = PASSWORD('${MYSQL_ROOT_PASSWD}') WHERE User = 'root';
EOF
    fi

    echo '' > ${MYSQL_INIT_SQL}

    cat >> ${MYSQL_INIT_SQL} <<EOF
-- Delete anonymouse user.
USE mysql;

DELETE FROM user WHERE User='';
DELETE FROM db WHERE User='';
EOF

    ECHO_DEBUG "Initialize MySQL database."
    ${MYSQL_CLIENT_ROOT} <<EOF
SOURCE ${MYSQL_INIT_SQL};
FLUSH PRIVILEGES;
EOF

    cat >> ${TIP_FILE} <<EOF
MySQL:
    * Root user: ${MYSQL_ROOT_USER}, Password: ${MYSQL_ROOT_PASSWD}
    * Bind account (read-only):
        - Username: ${VMAIL_DB_BIND_USER}, Password: ${VMAIL_DB_BIND_PASSWD}
    * Vmail admin account (read-write):
        - Username: ${VMAIL_DB_ADMIN_USER}, Password: ${VMAIL_DB_ADMIN_PASSWD}
    * RC script: ${MYSQLD_RC_SCRIPT}
    * See also:
        - ${MYSQL_INIT_SQL}

EOF

    echo 'export status_mysql_initialize="DONE"' >> ${STATUS_FILE}
}

# It's used only when backend is MySQL.
mysql_import_vmail_users()
{
    ECHO_DEBUG "Generating SQL template for postfix virtual hosts: ${MYSQL_VMAIL_SQL}."
    export DOMAIN_ADMIN_PASSWD="$(generate_password_hash ${DEFAULT_PASSWORD_SCHEME} ${DOMAIN_ADMIN_PASSWD})"
    export FIRST_USER_PASSWD="$(generate_password_hash ${DEFAULT_PASSWORD_SCHEME} ${FIRST_USER_PASSWD})"

    # Generate SQL.
    # Modify default SQL template, set storagebasedirectory.
    perl -pi -e 's#(.*storagebasedirectory.*DEFAULT).*#${1} "$ENV{STORAGE_BASE_DIR}",#' ${MYSQL_VMAIL_STRUCTURE_SAMPLE}
    perl -pi -e 's#(.*storagenode.*DEFAULT).*#${1} "$ENV{STORAGE_NODE}",#' ${MYSQL_VMAIL_STRUCTURE_SAMPLE}

    # Mailbox format is 'Maildir/' by default.
    cat >> ${MYSQL_VMAIL_SQL} <<EOF
/* Create database for virtual hosts. */
CREATE DATABASE IF NOT EXISTS ${VMAIL_DB} CHARACTER SET utf8;

/* Permissions. */
GRANT SELECT ON ${VMAIL_DB}.* TO "${VMAIL_DB_BIND_USER}"@"${MYSQL_GRANT_HOST}" IDENTIFIED BY "${VMAIL_DB_BIND_PASSWD}";
GRANT SELECT,INSERT,DELETE,UPDATE ON ${VMAIL_DB}.* TO "${VMAIL_DB_ADMIN_USER}"@"${MYSQL_GRANT_HOST}" IDENTIFIED BY "${VMAIL_DB_ADMIN_PASSWD}";

/* Initialize the database. */
USE ${VMAIL_DB};
SOURCE ${MYSQL_VMAIL_STRUCTURE_SAMPLE};

/* Add your first domain. */
INSERT INTO domain (domain,transport,settings,created) VALUES ("${FIRST_DOMAIN}", "${TRANSPORT}", "default_user_quota:1024;", NOW());

/* Add your first normal user. */
INSERT INTO mailbox (username,password,name,maildir,quota,domain,isadmin,isglobaladmin,created) VALUES ("${FIRST_USER}@${FIRST_DOMAIN}","${FIRST_USER_PASSWD}","${FIRST_USER}","${FIRST_USER_MAILDIR_HASH_PART}",1024, "${FIRST_DOMAIN}", 1, 1, NOW());
INSERT INTO alias (address,goto,domain,created) VALUES ("${FIRST_USER}@${FIRST_DOMAIN}", "${FIRST_USER}@${FIRST_DOMAIN}", "${FIRST_DOMAIN}", NOW());

/* Mark first mail user as global admin */
INSERT INTO domain_admins (username,domain,created) VALUES ("${DOMAIN_ADMIN_NAME}@${FIRST_DOMAIN}","ALL", NOW());

EOF

    ECHO_DEBUG "Import postfix virtual hosts/users: ${MYSQL_VMAIL_SQL}."
    ${MYSQL_CLIENT_ROOT} <<EOF
SOURCE ${MYSQL_VMAIL_SQL};
FLUSH PRIVILEGES;
EOF

    cat >> ${TIP_FILE} <<EOF
Virtual Users:
    - ${MYSQL_VMAIL_STRUCTURE_SAMPLE}
    - ${MYSQL_VMAIL_SQL}

EOF

    echo 'export status_mysql_import_vmail_users="DONE"' >> ${STATUS_FILE}
}

mysql_cron_backup()
{
    ECHO_INFO "Setup daily cron job to backup SQL databases: ${BACKUP_SCRIPT_MYSQL}"

    [ ! -d ${BACKUP_DIR} ] && mkdir -p ${BACKUP_DIR} >> ${INSTALL_LOG} 2>&1

    backup_file ${BACKUP_SCRIPT_MYSQL}
    cp ${TOOLS_DIR}/backup_mysql.sh ${BACKUP_SCRIPT_MYSQL}
    chown ${SYS_ROOT_USER}:${SYS_ROOT_GROUP} ${BACKUP_SCRIPT_MYSQL}
    chmod 0700 ${BACKUP_SCRIPT_MYSQL}

    export MYSQL_ROOT_PASSWD MYSQL_BACKUP_DATABASES
    perl -pi -e 's#^(export BACKUP_ROOTDIR=).*#${1}"$ENV{BACKUP_DIR}"#' ${BACKUP_SCRIPT_MYSQL}
    perl -pi -e 's#^(export MYSQL_USER=).*#${1}"$ENV{MYSQL_ROOT_USER}"#' ${BACKUP_SCRIPT_MYSQL}
    perl -pi -e 's#^(export MYSQL_PASSWD=).*#${1}"$ENV{MYSQL_ROOT_PASSWD}"#' ${BACKUP_SCRIPT_MYSQL}
    perl -pi -e 's#^(export DATABASES=)(.*)#${1}"$ENV{MYSQL_BACKUP_DATABASES}"#' ${BACKUP_SCRIPT_MYSQL}

    # Add cron job
    cat >> ${CRON_SPOOL_DIR}/root <<EOF
# ${PROG_NAME}: Backup MySQL databases on 03:30 AM
30   3   *   *   *   ${SHELL_BASH} ${BACKUP_SCRIPT_MYSQL}

EOF

    cat >> ${TIP_FILE} <<EOF
Backup MySQL database:
    * Script: ${BACKUP_SCRIPT_MYSQL}
    * See also:
        # crontab -l -u ${SYS_ROOT_USER}
EOF

    echo 'export status_mysql_cron_backup="DONE"' >> ${STATUS_FILE}
}

7

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

agodinho wrote:

mysql_generate_defauts_file_root()
{
    if [ X"${BACKEND_ORIG}" == X'MARIADB' ]; then
        ECHO_INFO "Configure MariaDB database server."
    else
        ECHO_INFO "Configure MySQL database server."
    fi
    ECHO_DEBUG "Generate temporary defauts file for MySQL client option --defaults-file: ${MYSQL_DEFAULTS_FILE_ROOT}."
    cat >> ${MYSQL_DEFAULTS_FILE_ROOT} <<EOF
[client]
user=${MYSQL_ROOT_USER}
password="${MYSQL_ROOT_PASSWD}"
EOF
    if [ X"${LOCAL_ADDRESS}" != X'127.0.0.1' -o X"${MYSQL_SERVER}" != X'127.0.0.1' ]; then
        cat >> ${MYSQL_DEFAULTS_FILE_ROOT} <<EOF
host=${MYSQL_SERVER}
port=${MYSQL_SERVER_PORT}
EOF
    fi
}

The most important part is this. It looks just fine.

agodinho wrote:

+ < DEBUG > Sleep 5 seconds for MySQL daemon initialization ...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Show me your /usr/local/etc/my.cnf please.

8

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

#---------------------------------------------------------------------
# This file is part of iRedMail, which is an open source mail server
# solution for Red Hat(R) Enterprise Linux, CentOS, Debian and Ubuntu.
#
# iRedMail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iRedMail is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iRedMail.  If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------

#
# Sample MySQL configuration file. It should be localted at:
#
#   - RHEL/CentOS:  /etc/my.cnf
#   - FreeBSD (www/mysql56-server): /var/db/mysql/my.cnf
#
# Shipped within iRedMail project:
#   http://www.iredmail.org/
#

[mysqld]
#bind-address            = 127.0.0.1
port                    = 3306
#default-character-set   = utf8
#datadir                 = /var/lib/mysql
#socket                  = /var/lib/mysql/mysql.sock
#user                    = mysql

#general_log = 1
#general_log_file = /var/log/mysql.log

#slow_query_log
#slow_query_log_file = /var/log/mysql_slow.log

skip-external-locking
#skip-bdb
#skip-networking

query-cache-type    = 1
# Use up to 64Mb of RAM to store query results.
query-cache-size    = 64M
query_cache_limit   = 10M

thread_cache_size   = 8

#max_connections=1024
#max_connect_errors=150

# If you got error message like "The total number of locks exceeds the lock tabl  e size",
# please try to increase 'innodb_buffer_pool_size' to a reasonable value.
# Restarting MySQL server is required to make new value work.
# You can get current value with SQL command:
#
#   mysql> SHOW ENGINE INNODB STATUS \G
#          [...]
#          Buffer pool size   512
#          [...]
#
#innodb_buffer_pool_size=512M

# Creates each new table using its own .ibd file for storing data and indexes,
# rather than in the system tablespace (ibdata*).
# Reference:
# http://dev.mysql.com/doc/refman/5.5/en/ … _innodb_fi  le_per_table
innodb_file_per_table

#ssl-ca =
#ssl-cert =
#ssl-key =
#ssl-cipher = ALL

[client]
default-character-set=utf8

#[mysql.server]
#user        = mysql
#basedir     = /var/lib

#[mysqld_safe]
#log-error   = /var/log/mysqld.log
#pid-file    = /var/run/mysqld/mysqld.pid

9

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

This is the MySQL log at /var/db/MySQL, file ending in .err

151015 11:48:09 mysqld_safe mysqld from pid file /var/db/mysql/mail.pid ended
151015 12:03:00 mysqld_safe Starting mysqld daemon with databases from /var/db/mysql
2015-10-15 12:03:04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-10-15 12:03:04 0 [Note] /usr/local/libexec/mysqld (mysqld 5.6.26) starting as process 7593 ...
2015-10-15 12:03:04 7593 [Note] Plugin 'FEDERATED' is disabled.
2015-10-15 12:03:04 7593 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-10-15 12:03:04 7593 [Note] InnoDB: The InnoDB memory heap is disabled
2015-10-15 12:03:04 7593 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-10-15 12:03:04 7593 [Note] InnoDB: Memory barrier is not used
2015-10-15 12:03:04 7593 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-10-15 12:03:04 7593 [Note] InnoDB: Using CPU crc32 instructions
2015-10-15 12:03:04 7593 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-10-15 12:03:04 7593 [Note] InnoDB: Completed initialization of buffer pool
2015-10-15 12:03:04 7593 [Note] InnoDB: Highest supported file format is Barracuda.
2015-10-15 12:03:05 7593 [Note] InnoDB: 128 rollback segment(s) are active.
2015-10-15 12:03:05 7593 [Note] InnoDB: Waiting for purge to start
2015-10-15 12:03:05 7593 [Note] InnoDB: 5.6.26 started; log sequence number 1626077
2015-10-15 12:03:05 7593 [Note] Server hostname (bind-address): '*'; port: 3306
2015-10-15 12:03:05 7593 [Note] IPv6 is available.
2015-10-15 12:03:05 7593 [Note]   - '::' resolves to '::';
2015-10-15 12:03:05 7593 [Note] Server socket created on IP: '::'.
2015-10-15 12:03:05 7593 [Note] Event Scheduler: Loaded 0 events
2015-10-15 12:03:05 7593 [Note] /usr/local/libexec/mysqld: ready for connections.
Version: '5.6.26'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution

10

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

Tested with latest iRedMail development edition, works fine. I will try iRedMail-0.9.2 again.

11

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

Could you please download iRedMail-0.9.2 below and try again? i fixed 2 issues mentioned in old forum threads and re-packed it, please let me know whether or not it works for you.
https://bitbucket.org/zhb/iredmail/downloads

12

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

Does this mean I have to reinstall the FreeBSD? or can I remove all ports and install iredmail?

13

Re: FreeBSD fresh install ERROR 2002 (HY000): Can't connect to local MySQL

Unfortunately, you have to reinstall FreeBSD and iRedMail.