Changes between Initial Version and Version 1 of howto/MySQL


Ignore:
Timestamp:
Dec 29, 2014, 2:51:55 AM (9 years ago)
Author:
magill@…
Comment:

new - extract and revision from MAMP

Legend:

Unmodified
Added
Removed
Modified
  • howto/MySQL

    v1 v1  
     1[[PageOutline]]
     2
     3[wiki:howto <- Back to the HOWTO section]
     4
     5This page describes the installation of the '''MySQL server''' under OSX (Yosemite 10.10.2) via MacPorts (version 2.3).   Date 28 December 2014
     6
     7For information on integration '''Apache''' with '''MySql''' and '''PhP''', see:''' [[howto/MAMP]]'''
     8
     9
     10= Step 1: Install MySQL = #mysql
     11
     12If you want to run a MySQL server on this computer, install MySQL like this:
     13{{{
     14sudo 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.
     20It does NOT produce the equivalent path of the path command below.
     21Which begs the question -- does the "OR" need to be "AND" or is the path command completely redundant.
     22I have assumed "AND" as the PATH needed to be set for me.
     23Does this make links in /opt/local/bin for /opt/local/lib/mysql56/bin/ files?
     24
     25sudo port select mysql mysql56
     26
     27generates the output:
     28
     29Selecting 'mysql56' for 'mysql' succeeded. 'mysql56' is now active.
     30
     31but makes no changes to the PATH.
     32}}}
     33
     34Also, 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{{{
     36sudo port select mysql mysql56
     37
     38export PATH=$PATH:/opt/local/lib/mysql56/bin
     39}}}
     40Once you have done at least one of the two previous commands, set up the main database:
     41
     42{{{
     43sudo -u _mysql mysql_install_db
     44sudo chown -R _mysql:_mysql /opt/local/var/db/mysql56/
     45sudo chown -R _mysql:_mysql /opt/local/var/run/mysql56/
     46sudo chown -R _mysql:_mysql /opt/local/var/log/mysql56/
     47}}}
     48
     49= Step 3: Activate the installation =
     50Activate your MySQL server installation so that it autostarts when you boot your machine:
     51{{{
     52sudo port load mysql56-server
     53}}}
     54
     55and then verify that it is running:
     56{{{
     57ps -ax | grep mysql
     58}}}
     59= Step 4: Set the MySQL password =
     60Set 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}}}
     64Note: This command line form of the command will generate:
     65 ''Warning: Using a password on the command line interface can be insecure.''
     66Therefore 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
     74You will first be prompted for your existing password (''Enter password:''); since it is empty, just press Return.\\
     75Then  <new-password>`is your new desired root password, followed by Return.
     76
     77Test everything by logging in to the server.
     78{{{
     79mysql -u root -p
     80}}}
     81You will be prompted:
     82 ''Enter password:''
     83Enter your <new password>
     84
     85Should you receive the message:
     86 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
     87It means you have entered the wrong password. Try again.
     88
     89Once you are logged in, simply exit the session like this:
     90{{{
     91mysql> exit ;
     92}}}
     93
     94If desired, reboot your machine and then run:
     95{{{
     96ps -ax | grep mysql
     97}}}
     98again to verify that the daemon is again running.
     99
     100= Step 5:  Optional security configuration = #mysql_security
     101
     102There 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
     109The 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
     124UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
     125DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';
     126DELETE FROM mysql.user WHERE User='';
     127FLUSH PRIVILEGES;
     128DROP DATABASE test;
     129DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
     130}}}
     131
     132The server startup options {{{--skip-networking}}} and {{{--skip-grant-tables}}} may be useful while implementing security. 
     133
     134See 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
     139If the database exists from a previous installation, you may need to upgrade.
     140
     141{{{
     142man mysql_upgrade  -- details on the upgrade program (man page)
     143sudo port unload mysql56-server
     144sudo /opt/local/lib/mysql5/bin/mysql_upgrade -u root -p
     145sudo port load mysql56-server
     146}}}
     147== Starting and stopping the MySQL server ==
     148=== Start ===
     149{{{
     150sudo port load mysql-server56
     151}}}
     152=== Stop ===
     153{{{
     154sudo port unload mysql-server56
     155}}}
     156
     157
     158[wiki:howto <- Back to the HOWTO section]