<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000099" bgcolor="#FFFFCC">
    <div class="moz-cite-prefix">On 3/11/19 12:10 AM, MacPorts wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:faceaa30-6aef-2ef4-e909-9f215fd49c04@hyperbole-software.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <span><span><span class="bold highlight search-highlight"><span><span
                class="bold highlight search-highlight"><span><span><span
                      class="bold highlight search-highlight"><span><span
                          class="bold highlight search-highlight"><span><span><span
                                class="bold highlight search-highlight"><span><span
                                    class="bold highlight
                                    search-highlight"></span></span></span></span></span></span></span></span></span></span>
              </span></span></span></span></span><br>
      <span><span><span class="bold highlight search-highlight"><span><span
                class="bold highlight search-highlight"></span></span></span></span></span>
      <blockquote type="cite">I found this thread: <a
          class="moz-txt-link-freetext"
href="http://mac-os-forge.2317878.n4.nabble.com/bp-seqfeature-load-pl-module-cannot-connect-to-mysql-td140155.html"
          moz-do-not-send="true">http://mac-os-forge.2317878.n4.nabble.com/bp-seqfeature-load-pl-module-cannot-connect-to-mysql-td140155.html</a>
        which recommends that you create a link from
        /var/mysql/mysql.sock to <span>/opt/local/var/run/</span><span><span
            class="bold highlight search-highlight">mysql5.<br>
               ( you may need to sudo mkdir -v </span></span><span><span
            class="bold highlight search-highlight"><span>/opt/local/var/run/</span><span><span
                class="bold highlight search-highlight">mysql5 first)</span></span></span></span><br>
           $ <span>sudo ln -s /var/<span class="bold highlight
            search-highlight">mysql</span>/<span class="bold highlight
            search-highlight">mysql</span>.sock </span><span><span><span
              class="bold highlight search-highlight"><span>/opt/local/var/run/</span><span><span
                  class="bold highlight search-highlight">mysql5<br>
                  <br>
                  I make the link, but Perl still c</span></span></span></span></span>an't
        connect to local MySQL server through socket
        '/opt/local/var/run/mysql57/mysqld.sock'.<br>
        <br>
      </blockquote>
      <br>
    </blockquote>
    I found several comments on the InterNET that suggested creating a
    link from the socket to the directory where Perl expects the port to
    be. I tried to do this in several different ways. None of them
    worked.<br>
    <br>
    I'm going to detail here what I did so if someone has this same
    question they will know what I tried that didn't work.<br>
    <br>
    First I tried<br>
       $ sudo ln -s /var/mysql/mysql.sock
    /opt/local/var/run/mysql57/mysqld.sock<br>
    this created a link in .../mysql57 owned by root:admin with
    permissions lrwxr-xr-x<br>
    <br>
    I assumed it wasn't working because the socket needed to be owned by
    _mysql:wheel so I<br>
       $ sudo chown _mysql:wheel mysql57/mysqld.sock<br>
    the ownership did not change.<br>
    I also tried 'sudo chown mysql:wheel mysql57/mysqld.sock' and the
    ownership didn't change.<br>
    <br>
    Since the sticky bit is set on the socket, and was not set on the
    link, i tried<br>
       $ sudo chmod +t mysql57/mysqld.sock<br>
    Perl still could not connect to the socket.<br>
    <br>
    I tried<br>
       $ sudo ln -s /var/mysql /opt/local/var /opt/local/var/run/mysql57<br>
    this created a link from the directory the socket resides in to the
    directory where Perl expects to find the socked. Then I created a
    link in /var/mysql from mysql.sock to mysqld.sock<br>
       $ cd /var/mysql<br>
       $ sudo ln -s mysql.sock mysqld.sock<br>
    This created sockets called mysql.sock, and mysqld.sock in
    .../mysql57. The socket called mysqld.sock was owned by root:admin
    with permissions lrwxr-xr-x and still gave an error when trying to
    connect Perl to the Database.<br>
    <br>
    Because of the problems with ownership/permissions, I removed
    mysqld.sock and created a hard link<br>
       $ sudo ln mysql.sock mysqld.sock<br>
    This created a socket in /opt/local/var/run/mysql57 with the correct
    name (mysqld.sock), the proper ownership (_mysql:wheel), and the
    proper permissions (srwxrwxrwt (notice the 'socket bit', and the
    sticky bit are both set)).<br>
    Perl still could not connect.<br>
    <br>
    All of these give the error:<br>
       Can't connect to local MySQL server through socket
    '/opt/local/var/run/mysql57/mysqld.sock' (2)<br>
    Notice the error code ENOENT(2), which means 'No such file or
    directory'. I don't understand why Perl thinks the socket (or the
    path to it) is missing.<br>
    <br>
    After creating the links, I tried<br>
       $ nc -U /opt/local/var/run/mysql57/mysqld.sock<br>
    This created output showing that MySQL was asking for a password. I
    also tried this command on the socket itself, and the link to the
    socket in /var/mysql. All of them showed MySQL requesting a
    password.<br>
    <br>
    <br>
    It would have been nice if creating a link to the socket had worked
    because I could run Perl on this machine without having to modify
    the programs when copying them to other machines. However, links on
    macOS do work differently than on Linux.<br>
       $ echo 'file1' > file1<br>
       $ ln -s file1 link1<br>
       $ cat link1<br>
          file1<br>
       $ mv file1 file2<br>
       $ echo 'fileb' > file1<br>
       $ cat link1<br>
          fileb<br>
    <br>
    This will also work if you remove the first file1, then create a new
    file1. This is what most text editors (vi, vim, emacs) will do. They
    move the original file to a temporary file, name the edited file the
    original name, and remove the temporary file. This is how symbolic
    links work on macOS. On Linux, this will break symbolic links.<br>
    <br>
    This difference between the way Linux and macOS handle links may be
    why some people only need to create a link to the socket for Perl to
    find it, but it doesn't work on macOS. If someone knows more about
    this please let me know.<br>
    <br>
    <br>
    What did work to connect Perl to MySQL was to put
    'mysql_socket=/var/mysql/mysql.sock' into the $dsn string for<br>
       $dbh = DBI->connect($dsn, $db_user_id, $db_password)<br>
          Note: The $dsn is a semi-colon (;) separated string of
    database name; hostname; socket, etc. Look at <span itemprop="name">DBD::mysql
      on<br>
                      metacpan.org for more information about the
      content of $dsn strings.</span><br>
    <br>
    The problem with this solution is that it means changing the
    connection code for every computer where the socket is stored in a
    different place, a real possibility when moving from macOS, to
    different flavors of Linux.<br>
    <br>
    The other solution, as suggested by Stephen Butler, is to set
    'mysql_read_default_file=/etc/my.cnf' in the $dsn string. It still
    means that you will need to change the code if the MySQL
    configuration file is in /etc/mysql/my.cnf, or somewhere else, but
    it allows for more flexibility than hard coding the path to the
    socket. I'm using this method in my code.<br>
    <br>
    <br>
    <br>
    Carl.<br>
    <br>
    <br>
    <br>
  </body>
</html>