About MySQL

Versions

MacPorts includes several versions of MySQL and some of its forks. You can install any or all of these versions simultaneously, though it is expected that you will only need to install one of them.

MySQL

mysql57: MySQL v5.7.x. This is the latest stable version of MySQL.

mysql56: MySQL v5.6.x.

mysql55: MySQL v5.5.x.

mysql51: MySQL v5.1.x. This version reached ​end of life at the end of 2013 and is therefore no longer recommended.

MariaDB: a fork of MySQL created by the original MySQL developer after MySQL AB's acquisition by Sun Microsystems

mariadb-10.1: MariaDB v10.1.x. This is a development version of MariaDB not recommended for production use.

mariadb-10.0: MariaDB v10.0.x. This is the latest stable version of MariaDB.

mariadb: MariaDB v5.5.x.

Percona: another MySQL fork

percona: Percona Server v5.6.x.

For each of the above ports, there is a "-server" companion port you should install if you want to run that server.

This page shows how to install and use the mysql56 port, but you can use another version if you prefer; all of these ports use a similar directory layout.

Step 1: Install MySQL

If you want to run a MySQL server on this computer, install MySQL like this:

$ sudo port install mysql57-server

Step 2: Create a database

Also, mysql57 now uses the ''port select'' mechanism to manage the creation of symlinks in
/opt/local/bin. Using port select will install a link for exactly one of the available
installations. Alternatively, you may simply add the path containing the desired mysql
installation to your PATH.

Step 4: Set the MySQL password

Set the MySQL root password (use the auto-generated password from the --initialize command above for MySQL 5.7. For MySQL 5.6 and earlier the password should currently be empty; see also the security option below):

You will first be prompted for your existing password (Enter password:); enter the root password (auto generated or no entry depending on your MySQL version) then press Return.
Then <new-password>`is your new desired root password, followed by Return.

Step 5: Optional security configuration

The following is a more detailed process that may achieve the same results as the interactive program. Place the following into mysql_security.sql and replace the 'MyNewPass' with your root password. Note that the SQL will remove all access for root from any location other than 'localhost'. You might like to keep this SQL file - all the lines beginning with '--' are doc-comments about how to use it.

Wrapper no longer exists...

-- HOW TO USE THIS FILE (with a MacPorts installation):
--$ sudo port unload mysql57-server
-- $ sudo mysqld_safe --init-file=mysql_security.sql &
-- The init will terminate if there are any errors in the init file.
-- Wait a bit to be sure the server is running.
-- If it's running, then shutdown the server (root password required):
-- $ /opt/local/bin/mysqladmin -u root -p shutdown
-- Check that everything worked. There may be an ERROR if the test database
-- doesn't exist. Otherwise there should be no errors in the file reported by
-- 'mysqld_safe Logging to ..." during the mysql_safe5 startup from above:
-- $ sudo tail -n 20 /opt/local/var/db/mysql5*.err
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';
DELETE FROM mysql.user WHERE User='';
FLUSH PRIVILEGES;
DROP DATABASE test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';

The server startup options --skip-networking and --skip-grant-tables may be useful while implementing security.