2014-02-16 wcdj
摘要:本文记录在Mac OS X 10.9.1(x86, 64-bit)上配置MySQL数据库的安装过程,以及记录的一些问题。
0 下载
打开官网地址 http://www.mysql.com/ ,然后点击 Downloads (GA) 进入下载页面,其中commercial是商业付费的,GPL(https://www.gnu.org/copyleft/gpl.html)是开源免费的,所以找到Mysql Community Edition(GPL) 点击进入可以找到下面这个下载链接:
进入后可以看到关于“
Download MySQL Community Server
”的一段描述:
“MySQL Community Edition is a freely downloadable version of the world's most popular open source database that is supported by an active community of open source developers and enthusiasts.”
并在下面可以看到网页自动识别出当前的操作系统对应的MySQL版本:
在这里并没有找到最新的Mac OS X 10.9所对应的版本(当前OS的版本可以通过 sw_vers 命令查看):
gerryyang@mba:MySQL$sw_vers
ProductName:Mac OS X
ProductVersion:10.9.1
BuildVersion:13B42
然后,google了一下在github上找到一个Mac上自动安装MySQL的脚本,发现作者用的也不是最新的版本而是10.7的dmg版本,关于此脚本的用法,作者的一些文章介绍链接如下:
“
Mac-Scripts
Automation scripts focused around Mac OS X Server
Install MySQL on OS X 10.9 Mavericks
http://www.macminivault.com/mysql-mavericks/
Install MySQL on Mountain Lion
http://www.macminivault.com/mysql-mountain-lion/
http://code.macminivault.com/
https://github.com/MacMiniVault/Mac-Scripts
https://raw.github.com/MacMiniVault/Mac-Scripts/master/mmvMySQL/mmvmysql.sh
”
下文继续使用官方提供的链接进行安装(注释:这里使用的是二进制的安装方式),脚本的方法这里不讨论(脚本中的下载链接:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.15-osx10.7-x86_64.dmg)。
下载过程有点慢,可以使用shutdown命令设定关机或休眠:
gerryyang@mba:Volumes$sudo shutdown -s 1402150045
Password: Shutdown at Sat Feb 15 00:45:00 2014.
shutdown: [pid 5261]
如果想取消自动关机,使用 sudo kill pid 命令即可。
1 安装
下文假设已经下载完毕。为了叙述方便,下文采用命令交互的方法记录整个安装和测试过程:
(1) MySQL的INSTALL_BINARY安装说明建议创建一个mysql User and Group,OS X的命令和Linux的有所不同,通过下面命令可以创建:
# 创建mysql用户
dscl . -create /Users/mysql
# 设置使用的shell
dscl . -create /Users/mysql UserShell /bin/bash
# 设置用户home目录
dscl . -create /Users/mysql NFSHomeDirectory /Users/mysql
# 设置密码
dscl . -passwd /Users/mysql mysql
(2) 对MySQL进行初始化,创建系统需要的表。This scripts creates the MySQL Server system tables.
root@mba:mysql-5.6.16-osx10.7-x86#scripts/mysql_install_db --user=mysql
(3) 使用root用户启动MySQL,并通过ps查看进程是否正常被拉起
gerryyang@mba:mysql-5.6.16-osx10.7-x86$su root
Password:
root@mba:mysql-5.6.16-osx10.7-x86#bin/mysqld_safe &
[1] 8679
root@mba:mysql-5.6.16-osx10.7-x86#140216 19:46:16 mysqld_safe Logging to '/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data/mba.local.err'.
140216 19:46:16 mysqld_safe Starting mysqld daemon with databases from /Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data
root@mba:mysql-5.6.16-osx10.7-x86#ps aux | grep mysql | grep -v grep
_mysql 8757 0.0 10.4 1211616 435524 s001 S 7:46下午 0:00.39 /Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/bin/mysqld --basedir=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86 --datadir=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data --plugin-dir=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/lib/plugin --user=mysql --log-error=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data/mba.local.err --pid-file=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data/mba.local.pid
root 8679 0.0 0.0 2452820 1140 s001 S 7:46下午 0:00.03 /bin/sh bin/mysqld_safe
root@mba:mysql-5.6.16-osx10.7-x86#
(4) 使用kill -9 pid干掉MySQL,这里要先把mysqld_safe进程干掉,然后再把mysql进程干掉,否则mysql会被重新拉起
root@mba:mysql-5.6.16-osx10.7-x86#kill -9 8679
root@mba:mysql-5.6.16-osx10.7-x86#ps aux | grep mysql | grep -v grep
_mysql 8757 0.0 10.4 1211616 435524 s001 S 7:46下午 0:00.45 /Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/bin/mysqld --basedir=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86 --datadir=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data --plugin-dir=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/lib/plugin --user=mysql --log-error=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data/mba.local.err --pid-file=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data/mba.local.pid
[1]+ Killed: 9 bin/mysqld_safe
root@mba:mysql-5.6.16-osx10.7-x86#kill -9 8757
root@mba:mysql-5.6.16-osx10.7-x86#ps aux | grep mysql | grep -v grep
root@mba:mysql-5.6.16-osx10.7-x86#bin/mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61)
(5) 为了方便,将MySQL/bin加入PATH环境变量中,修改用户home目录下的.bashrc文件,添加如下内容,然后在终端执行 . .bashrc 命令使其生效
# MySQL
export MYSQL_PATH=/Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86
export PATH=$PATH:$MYSQL_PATH/bin
gerryyang@mba:~$whoami
gerryyang
gerryyang@mba:~$mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
mysql> \q
Bye
gerryyang@mba:~$su root
Password:
root@mba:gerryyang#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.10 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
28 rows in set (0.00 sec)
mysql> select distinct Host, User, Password from user;
+-----------+------+----------+
| Host | User | Password |
+-----------+------+----------+
| localhost | root | |
| mba.local | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| mba.local | | |
+-----------+------+----------+
6 rows in set (0.00 sec)
mysql> select count(1) from user;
+----------+
| count(1) |
+----------+
| 6 |
+----------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.16 |
+-----------+
1 row in set (0.00 sec)
2 参考
[1] http://blog.microsuncn.com/?p=3604 (在Mac下如何创建用户)