Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As a total newbie I am trying to get through this tutorial:

I'm at the point where I've used brew install MySQL and have this version installed: mysql-5.6.10. I am running python 2.7

When I try to run mysqld in terminal to start the server I get this error:

Davids-MacBook-Pro:~ David$ mysqld
2013-03-17 18:20:28 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-03-17 18:20:28 3818 [Warning] Can't create test file /usr/local/var/mysql/Davids-MacBook-Pro.lower-test
2013-03-17 18:20:28 3818 [Warning] Can't create test file /usr/local/var/mysql/Davids-MacBook-Pro.lower-test
mysqld: Can't change dir to '/usr/local/var/mysql/' (Errcode: 2 - No such file or directory)
2013-03-17 18:20:28 3818 [ERROR] Aborting

2013-03-17 18:20:28 3818 [Note] Binlog end
2013-03-17 18:20:28 3818 [Note] mysqld: Shutdown complete
share|improve this question

migrated from Mar 18 '13 at 6:16

This question came from our site for professional and enthusiast programmers.

Does the folder /usr/local/var/mysql/ exist and having write permissions? – hjpotter92 Mar 17 '13 at 22:29
You might want to post this to "Ask Different" as a question about getting MySQL running on your Mac using Homebrew (the brew command). That sounds like it's more to the point. Once you have MySQL server running then the tutorial will probably go far more smoothly. – Jim Dennis Mar 17 '13 at 22:36
it doesn't look like it. I do cd /usr in terminal, then ls and don't see it "local". I think mysql is installed somewhere I think I need to figure out where? Sorry I am a total rookie, today was the first time i've ever even using terminal! – David Squires Mar 17 '13 at 22:37
I've changed your tag [brew] to [homebrew] as it appears that [brew] has nothing to do with MacOS nor with your question. – Jim Dennis Mar 17 '13 at 22:38
1… – catherine Mar 18 '13 at 3:08

I've just installed MySQL (same version as you've listed) using Homebrew and encountered problems similar to yours.

I will note that my copy of Homebrew is probably not healthy; brew doctor continues to give me warnings, especially about some alleged installation of MacPorts or fink, and I plan to re-image this old box from scratch at some point.

That said I hacked my way through the problem using the following:

mkdir /local/var/mysql

# From the `brew info mysql` command's output:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

(That's only three commands; ignore the # comment if you paste these into your terminal).

From there I ran mysqld_safe --skip-grant-tables in one terminal and, from another, connected to that server using mysql -u root. From there I ran:

UPDATE mysql.user SET Password=PASSWORD('**MY_NEW_PASSWORD**') WHERE User='root';

Exit out of the server session by clicking Ctrl-C and then I killed mysqld_safe using mysqladmin -u root -p shutdown and restarted MySQL with Homebrew's link: mysql.server start

That seems to have done the job. I don't know whether it will automatically start MySQL when I restart my Mac; but I don't want that anyway. If that works for you it should be enough to get you into the tutorial itself. You might have to open a terminal and run mysql.server start every time you want to work with your databases, of course ... and I'll let you search on adding it to launchctl on your own if that's what you want).

Note the part about running mysqld_safe --skip-grant-tables is a way of "breaking in" to your MySQL databases, enabling you to locally connect as the 'root' (MySQL super-user or admin) without knowing the old password). Other posts here on SO suggest that Homebrew should have set up the directory and set the initial password to "new-password" for you.

The UPDATE command I've shown here is part of the conventional process by which any MySQL admin would force a password recovery for any MySQL system where the root password had been lost. The database named "mysql" stores MySQL's own management tables, and the "user" table within that has columns for "Password" and "User." The PASSWORD() function takes plain text (the password as you intend to type it) and hashes it ... which is to say it performs a complex set of mathematical operations on a numerical encoding of the string/text which is similar to a "checksum." MySQL stores such hashes in the Password column of mysql.user rather than the plain text of the password itself.

Password hashing is a feature of almost all operating systems, database systems, and most other system and applications where passwords are used. If you eventually write web applications then it's very likely that you'll use some sort of hashing function for storing and checking passwords.

As I said, I use the command brew info mysql to get some suggestions about how to "fix" the installation of MySQL; you can use that command for any other stuff that you install through Homebrew if it doesn't seem to be working as you expect.

Heres' the other StackOverflow article which I used for further help:

I have intentionally over-explained some of these details because you've expressed that you are very novice at all of this.

(One of these days some really experience SO participant is going to tell me the preferred way to cross-link to other SO questions, answers, and comments).

share|improve this answer
Thanks very much for the detailed response Jim. Unfortunately I got stuck early this will help a lot. I try making the directory like you described but I'm getting a weird issue. I can't get in the /var directory but I also can't make one because it exists. Any ideas? – David Squires Mar 17 '13 at 23:57
Davids-MacBook-Pro:local David$ cd var -bash: cd: var: No such file or directory Davids-MacBook-Pro:local David$ sudo mkdir /var mkdir: /var: File exists – David Squires Mar 17 '13 at 23:59
David: Try sudo mkdir /usr/local/var/mysql; then sudo chown $(whoami) /usr/local/var/mysql. Those two command should, at least, create the necessary directory and ensure that you own it. From there you may have to try the whole process of installing MySQL (using brew) all over again. – Jim Dennis Mar 18 '13 at 0:01
I get "No such file or directory" after pasting the sudo mkdir command in. I'm lost! – David Squires Mar 18 '13 at 0:04

You must log in to answer this question.