• Resolved quequiereshacer

    (@quequiereshaceres)


    My WordPress was migrated to a VPS with a socket MySQL connection.

    Since that change Backupwordpress was giving this error when you try to make a database backup:

    “Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock'”

    In my case the socket path to connect to the MySQL server was defined in wp-config.php in this way:

    define(‘DB_HOST’, ‘localhost:/tmp/mysql5.sock’);

    I see Backupwordpress don’t support defining a custom socket path connection in this way, so to solve that I added a new line to the public function mysqldump() in the file /wp-content/plugins/backupwordpress/hm-backup/hm-backup.php after the line “$cmd .= ‘ –no-create-db’;”:

    // Socket connection defined in host
    $cmd .= ‘ –protocol=socket -S /tmp/mysql5.sock’;

    In my case the socket path is ‘/tmp/mysql5.sock’. Replace with your custom socket path.

    I hope it help to improve this excellent plugin. Thanks!

    https://ww.wp.xz.cn/plugins/backupwordpress/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter quequiereshacer

    (@quequiereshaceres)

    Hello again,

    I send you the code of the modified function to handle a custom socket path configuration:

    public function mysqldump() {
    
    		$this->mysqldump_method = 'mysqldump';
    
    		$this->do_action( 'hmbkp_mysqldump_started' );
    
    		$host = explode( ':', DB_HOST );
    
    		$host = reset( $host );
    		$port = strpos( DB_HOST, ':' ) ? end( explode( ':', DB_HOST ) ) : '';
    		$socket = strpos( DB_HOST, ':' ) ? end( explode( ':', DB_HOST ) ) : '';
    
    		// Path to the mysqldump executable
    		$cmd = escapeshellarg( $this->get_mysqldump_command_path() );
    
    		// We don't want to create a new DB
    		$cmd .= ' --no-create-db';
    
    		// Allow lock-tables to be overridden
    		if ( ! defined( 'HMBKP_MYSQLDUMP_SINGLE_TRANSACTION' ) || HMBKP_MYSQLDUMP_SINGLE_TRANSACTION !== false )
    			$cmd .= ' --single-transaction';
    
    		// Make sure binary data is exported properly
    		$cmd .= ' --hex-blob';
    
    		// Username
    		$cmd .= ' -u ' . escapeshellarg( DB_USER );
    
    		// Don't pass the password if it's blank
    		if ( DB_PASSWORD )
    			$cmd .= ' -p' . escapeshellarg( DB_PASSWORD );
    
    		// Set the host
    		$cmd .= ' -h ' . escapeshellarg( $host );
    
    		// Set the port if it was set
    		if ( ! empty( $port ) && is_numeric( $port ) )
    			$cmd .= ' -P ' . $port;
    
    		// Set the socket path
    		if ( ! empty( $socket ) && !is_numeric( $socket ) )
    			$cmd .= ' --protocol=socket -S ' . $socket;
    
    		// The file we're saving too
    		$cmd .= ' -r ' . escapeshellarg( $this->get_database_dump_filepath() );
    
    		// The database we're dumping
    		$cmd .= ' ' . escapeshellarg( DB_NAME );
    
    		// Pipe STDERR to STDOUT
    		$cmd .= ' 2>&1';
    
    		// Store any returned data in an error
    		$stderr = shell_exec( $cmd );
    
    		// Skip the new password warning that is output in mysql > 5.6 (@see http://bugs.mysql.com/bug.php?id=66546)
    		if ( trim( $stderr ) === 'Warning: Using a password on the command line interface can be insecure.' ) {
    			$stderr = '';
    		}
    
    		if ( $stderr ) {
    			$this->error( $this->get_mysqldump_method(), $stderr );
    		}
    
    		$this->verify_mysqldump();
    
    	}
    Plugin Contributor Paul de Wouters

    (@pauldewouters)

    thanks, we actually accept pull requests, so if you are familiar with Git and Github, it would be great if you could submit one.
    No worries if not.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Mysqldump custom socket path’ is closed to new replies.