| 1 | [[PageOutline]] |
| 2 | |
| 3 | [wiki:howto <- Back to the HOWTO section] |
| 4 | |
| 5 | This page describes the installation of the '''MySQL server''' under OSX (Yosemite 10.10.2) via MacPorts (version 2.3). Date 28 December 2014 |
| 6 | |
| 7 | For information on integration '''Apache''' with '''MySql''' and '''PhP''', see:''' [[howto/MAMP]]''' |
| 8 | |
| 9 | |
| 10 | = Step 1: Install MySQL = #mysql |
| 11 | |
| 12 | If you want to run a MySQL server on this computer, install MySQL like this: |
| 13 | {{{ |
| 14 | sudo port install mysql56-server |
| 15 | }}} |
| 16 | |
| 17 | = Step 2: create a database = |
| 18 | {{{ |
| 19 | '''NOTE:''' This needs a definition of the "Port Slect" mechanism. i.e. explain what it does. |
| 20 | It does NOT produce the equivalent path of the path command below. |
| 21 | Which begs the question -- does the "OR" need to be "AND" or is the path command completely redundant. |
| 22 | I have assumed "AND" as the PATH needed to be set for me. |
| 23 | Does this make links in /opt/local/bin for /opt/local/lib/mysql56/bin/ files? |
| 24 | |
| 25 | sudo port select mysql mysql56 |
| 26 | |
| 27 | generates the output: |
| 28 | |
| 29 | Selecting 'mysql56' for 'mysql' succeeded. 'mysql56' is now active. |
| 30 | |
| 31 | but makes no changes to the PATH. |
| 32 | }}} |
| 33 | |
| 34 | Also, mysql56 now uses the `''port select''` mechanism, so you will have to run one of the following to get the mysql commands in your PATH: either: |
| 35 | {{{ |
| 36 | sudo port select mysql mysql56 |
| 37 | |
| 38 | export PATH=$PATH:/opt/local/lib/mysql56/bin |
| 39 | }}} |
| 40 | Once you have done at least one of the two previous commands, set up the main database: |
| 41 | |
| 42 | {{{ |
| 43 | sudo -u _mysql mysql_install_db |
| 44 | sudo chown -R _mysql:_mysql /opt/local/var/db/mysql56/ |
| 45 | sudo chown -R _mysql:_mysql /opt/local/var/run/mysql56/ |
| 46 | sudo chown -R _mysql:_mysql /opt/local/var/log/mysql56/ |
| 47 | }}} |
| 48 | |
| 49 | = Step 3: Activate the installation = |
| 50 | Activate your MySQL server installation so that it autostarts when you boot your machine: |
| 51 | {{{ |
| 52 | sudo port load mysql56-server |
| 53 | }}} |
| 54 | |
| 55 | and then verify that it is running: |
| 56 | {{{ |
| 57 | ps -ax | grep mysql |
| 58 | }}} |
| 59 | = Step 4: Set the MySQL password = |
| 60 | Set the MySQL `root` password (it should currently be empty, see also the security option below): |
| 61 | {{{ |
| 62 | /opt/local/lib/mysql56/bin/mysqladmin -u root -p password <new-password> |
| 63 | }}} |
| 64 | Note: This command line form of the command will generate: |
| 65 | ''Warning: Using a password on the command line interface can be insecure.'' |
| 66 | Therefore it is recommended that you use the interactive form: |
| 67 | {{{ |
| 68 | /opt/local/lib/mysql56/bin/mysqladmin -u root -p password |
| 69 | }}} |
| 70 | ''Enter password:'' <press return> \\ |
| 71 | ''New password:'' <new password> \\ |
| 72 | ''Confirm new password:'' <new password> |
| 73 | |
| 74 | You will first be prompted for your existing password (''Enter password:''); since it is empty, just press Return.\\ |
| 75 | Then <new-password>`is your new desired root password, followed by Return. |
| 76 | |
| 77 | Test everything by logging in to the server. |
| 78 | {{{ |
| 79 | mysql -u root -p |
| 80 | }}} |
| 81 | You will be prompted: |
| 82 | ''Enter password:'' |
| 83 | Enter your <new password> |
| 84 | |
| 85 | Should you receive the message: |
| 86 | ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) |
| 87 | It means you have entered the wrong password. Try again. |
| 88 | |
| 89 | Once you are logged in, simply exit the session like this: |
| 90 | {{{ |
| 91 | mysql> exit ; |
| 92 | }}} |
| 93 | |
| 94 | If desired, reboot your machine and then run: |
| 95 | {{{ |
| 96 | ps -ax | grep mysql |
| 97 | }}} |
| 98 | again to verify that the daemon is again running. |
| 99 | |
| 100 | = Step 5: Optional security configuration = #mysql_security |
| 101 | |
| 102 | There is an interactive program to secure a MySQL installation. |
| 103 | |
| 104 | {{{ |
| 105 | $ man mysql_secure_installation |
| 106 | $ /opt/local/bin/mysql_secure_installation |
| 107 | }}} |
| 108 | |
| 109 | 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. |
| 110 | |
| 111 | {{{ |
| 112 | -- HOW TO USE THIS FILE (with a MacPorts installation): |
| 113 | -- $ sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop |
| 114 | -- $ sudo mysqld_safe --init-file=mysql_security.sql & |
| 115 | -- The init will terminate if there are any errors in the init file. |
| 116 | -- Wait a bit to be sure the server is running. |
| 117 | -- If it's running, then shutdown the server (root password required): |
| 118 | -- $ /opt/local/bin/mysqladmin -u root -p shutdown |
| 119 | -- Check that everything worked. There may be an ERROR if the test database |
| 120 | -- doesn't exist. Otherwise there should be no errors in the file reported by |
| 121 | -- 'mysqld_safe Logging to ..." during the mysql_safe5 startup from above: |
| 122 | -- $ sudo tail -n 20 /opt/local/var/db/mysql5/*.err |
| 123 | |
| 124 | UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; |
| 125 | DELETE FROM mysql.user WHERE User='root' AND Host!='localhost'; |
| 126 | DELETE FROM mysql.user WHERE User=''; |
| 127 | FLUSH PRIVILEGES; |
| 128 | DROP DATABASE test; |
| 129 | DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'; |
| 130 | }}} |
| 131 | |
| 132 | The server startup options {{{--skip-networking}}} and {{{--skip-grant-tables}}} may be useful while implementing security. |
| 133 | |
| 134 | See also http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-unix |
| 135 | |
| 136 | |
| 137 | = Step 6: Optional database upgrade = #mysql_upgrade |
| 138 | |
| 139 | If the database exists from a previous installation, you may need to upgrade. |
| 140 | |
| 141 | {{{ |
| 142 | man mysql_upgrade -- details on the upgrade program (man page) |
| 143 | sudo port unload mysql56-server |
| 144 | sudo /opt/local/lib/mysql5/bin/mysql_upgrade -u root -p |
| 145 | sudo port load mysql56-server |
| 146 | }}} |
| 147 | == Starting and stopping the MySQL server == |
| 148 | === Start === |
| 149 | {{{ |
| 150 | sudo port load mysql-server56 |
| 151 | }}} |
| 152 | === Stop === |
| 153 | {{{ |
| 154 | sudo port unload mysql-server56 |
| 155 | }}} |
| 156 | |
| 157 | |
| 158 | [wiki:howto <- Back to the HOWTO section] |