Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've just installed mysql5 myself, and since this is always a pain I've noted the process that I followed. This was done on Leopard, but I imagine the process is the same on Snow Leopard and Lion. It doesn't answer all the original questions, but at least it's something of a guide.</p> <h2>Installing Mysql</h2> <p>First, install mysql5 server with:</p> <pre><code>sudo port install mysql5-server </code></pre> <p>Just installing <code>mysql5</code> doesn't install the server.</p> <p>Pay attention to the console output, it includes instructions for setting up macports. You might want to copy and paste it to a text file. The following is based on it.</p> <p>Instead of <code>mysql5-server</code>, you could use a port such as <code>mysql55-server</code>, <code>mysql56-server</code>, <code>mariadb-server</code> or <code>percona-server</code> to get a more recent version of mysql, or a fork. If you do, pay attention to the console output, as the following instructions are based on <code>mysql5-server</code> and will need to be adjusted to use the correct executables and paths.</p> <p>If this is a new install, set up the database:</p> <pre><code>sudo -u _mysql mysql_install_db5 </code></pre> <p>That outputs some generic instructions, which I don't think are entirely appropriate for macports. In my opinion the best way to load mysql5 as a daemon is to use macport's method:</p> <pre><code>sudo port load mysql5-server </code></pre> <p>As well as starting mysql5, this permanently loads it - it will run on boot up. To stop this later:</p> <pre><code>sudo port unload mysql5-server </code></pre> <p>If you don't want to run it as a daemon, you can run it at the command line:</p> <pre><code>sudo /opt/local/lib/mysql5/bin/mysqld_safe </code></pre> <p>Check that it's running by logging in at the command line:</p> <pre><code>mysql5 -u root -p </code></pre> <p>By default, the password is empty, so just press enter when prompted. To set a root password:</p> <pre><code>/opt/local/lib/mysql5/bin/mysqladmin -u root password 'correct horse battery staple' </code></pre> <p>Instructions for setting up both macports php and the native php installation follow.</p> <h2>Setup Macports PHP</h2> <p>Assuming you've already got macports php installed and running. You need to install <code>php5-mysql</code> (or something like <code>php54-mysql</code> depending on which version of php you're using):</p> <pre><code>sudo port install php5-mysql </code></pre> <p>This installs the mysql, mysqli and pdo drivers.</p> <p>Now look in your <code>/opt/local/etc/php5</code> directory, if you don't already have a <code>php.ini</code> configuration file copy either <code>php.ini-development</code> or <code>php.ini-production</code> to <code>php.ini</code>. Now edit <code>php.ini</code> and search for the appropriate lines to add:</p> <pre><code>pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock </code></pre> <p>and:</p> <pre><code>mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock </code></pre> <p>and:</p> <pre><code>mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock </code></pre> <p>If you don't want to configure these, you can set them explicitly in your php script when you connect.</p> <p>If you're having trouble connecting you might want to look at the other nearby settings, and compare with <code>php.ini-development</code> and <code>php.ini-production</code> to see what's been changed.</p> <p>Then use the script below, or something similar to test that you can connect with php.</p> <h2>Setup System PHP</h2> <p>OS X's php comes with mysql and mysqli support built in (but not pdo), so all you need to do is set the macport unix socket. The default location is <code>/opt/local/var/run/mysql5/mysqld.sock</code>. Find the correct place in <code>/etc/php.ini</code> (if you don't have it already, copy it from <code>/etc/php.ini.default</code>) to add:</p> <pre><code>mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock </code></pre> <p>and:</p> <pre><code>mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock </code></pre> <p>If you don't want to configure these, you can set them explicitly in your php script when you connect.</p> <h2>Test Script</h2> <p>Here's a php script to check that it can connect. Obviously, you won't normally use the root account in your php scripts so you might want to first create another mysql account for testing the connection. The PDO connection won't work for native php since that doesn't have PDO drivers.</p> <pre><code>&lt;?php $username = 'root'; $password = 'correct horse battery staple'; /* Try mysql: */ $connection = mysql_connect('localhost', $username, $password); if ($connection === FALSE) { echo "Error connecting using mysql.\n\n"; echo "Error ".mysql_errno().": ".mysql_error()."\n\n"; } else { echo "Connected using mysql.\n\n"; mysql_close($connection); } /* Try mysqli: */ $connection = mysqli_connect('localhost', $username, $password); if ($connection-&gt;connect_error) { echo "Error connecting using mysqli:\n\n"; echo "Error ".$connection-&gt;connect_errno.": ".$connection-&gt;connect_error."\n\n"; } else { echo "Connected using mysqli.\n\n"; $connection-&gt;close(); } /* Try pdo: * Won't work for the version of php supplied with OS X. */ try { $pdo = new PDO('mysql:host=localhost', $username, $password); echo "Connected using PDO.\n\n"; $pdo = null; } catch(PDOException $e) { echo "Error connecting using PDO:\n\n"; echo "Error ".$e-&gt;getCode().": ".$e-&gt;getMessage()."\n\n"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload