Mac 开发配置学习手册



We will install MySQL using Homebrew, which will also install some header files needed for MySQL bindings in different programming languages (MySQL-Python for one).

To install, run:

$ brew update # Always good to do
$ brew install mysql

As you can see in the ouput from Homebrew, before we can use MySQL we first need to set it up with:

$ unset TMPDIR
$ mkdir /usr/local/var
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp


To start the MySQL server, use the mysql.server tool:

$ mysql.server start

To stop it when you are done, run:

$ mysql.server stop

You can see the different commands available for mysql.server with:

$ mysql.server --help

To connect with the command-line client, run:

$ mysql -uroot

(Use exit to quit the MySQL shell.)

Note: By default, the MySQL user root has no password. It doesn't really matter for a local development database. If you wish to change it though, you can use $ mysqladmin -u root password 'new-password'.