homebrew + mysql = installed but access denied for root
1. Cleanup
I have an existing mysql @ /usr/local/mysql, so we remove that.
% sudo rm -rf mysql-5.1.43-osx10.6-x86_64 |
Note: I suggest you backup your mysql data by doing mysqldump prior to removing the old mysql.
2. Install mysql
#brew install mysql Set up databases to run AS YOUR USER ACCOUNT with: unset TMPDIR mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp To set up base tables in another folder, or use a different user to run mysqld, view the help for mysqld_install_db: mysql_install_db --help and view the MySQL documentation: * http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html * http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html To run as, for instance, user "mysql", you may need to `sudo`: sudo mysql_install_db ...options... Start mysqld manually with: mysql.server start Note: if this fails, you probably forgot to run the first two steps up above A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly. To connect: mysql -uroot To launch on startup: * if this is your first install: mkdir -p ~/Library/LaunchAgents cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist * if this is an upgrade and you already have the com.mysql.mysqld.plist loaded: launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist You may also need to edit the plist to use the correct "UserName". Warning: m4 macros were installed to "share/aclocal". Homebrew does not append "/usr/local/share/aclocal" to "/usr/share/aclocal/dirlist". If an autoconf script you use requires these m4 macros, you'll need to add this path manually. ==> Summary /usr/local/Cellar/mysql/5.5.15: 6277 files, 217M, built in 4.9 minutes brew install mysql 498.39s user 83.40s system 135% cpu 7:08.37 total |
~/Desktop% unset TMPDIR ~/Desktop% echo $TMPDIR ~/Desktop% mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/Cellar/mysql/5.5.15/bin/mysqladmin -u root password 'new-password' /usr/local/Cellar/mysql/5.5.15/bin/mysqladmin -u root -h rupert-imac password 'new-password' Alternatively you can run: /usr/local/Cellar/mysql/5.5.15/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr/local/Cellar/mysql/5.5.15 ; /usr/local/Cellar/mysql/5.5.15/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/local/Cellar/mysql/5.5.15/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/local/Cellar/mysql/5.5.15/scripts/mysqlbug script! |
~/Desktop% which mysql.server /usr/local/bin/mysql.server ~/Desktop% ls -la `which mysql.server` lrwxr-xr-x 1 rupert admin 39 30 Dec 11:20 /usr/local/bin/mysql.server@ -> ../Cellar/mysql/5.5.15/bin/mysql.server ~/Desktop% mysql.server start Starting MySQL .. SUCCESS! |
3. That’s it? No.
At the time of writing this, mysql is at 5.5 and was installed successfully by homebrew. However, I cannot login using the root account. Have a read of this stackoverflow: brew install mysql on mac os.
To fix this, stop mysql
launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist |
and start mysql by skipping the grant tables.
mysqld_safe --skip-grant-tables |
Depending if you have a record in mysql.user (select * from mysql.user), then you can either create or update the user.
create:
GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' IDENTIFIED BY 'whatever' WITH GRANT OPTION; FLUSH PRIVILEGES; |
update:
UPDATE mysql.USER SET Password = PASSWORD('NewPassword') WHERE USER='root'; FLUSH PRIVILEGES; |
4. Cleanup paths
This is just removing the pgsql and mysql from the current path
export PATH=$PATH:$ORACLE_HOME:$MYSQL_HOME/bin:$CLANG_HOME:$ANDROID_HOME/tools:$APACHE2_HOME/bin:$MAGICK_HOME/bin:$SPHINX_HOME/bin:$PGSQL_HOME/bin |