SQL~在Mac OS X 10.9.1(x86, 64-bit)上配置MySQL数据库

0 篇文章 0 订阅

摘要:本文记录在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.

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. root@mba:mysql-5.6.16-osx10.7-x86#scripts/mysql_install_db --user=mysql  

(3) 使用root用户启动MySQL,并通过ps查看进程是否正常被拉起

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. gerryyang@mba:mysql-5.6.16-osx10.7-x86$su root  
  2. Password:  
  3. root@mba:mysql-5.6.16-osx10.7-x86#bin/mysqld_safe &  
  4. [1] 8679  
  5. 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'.  
  6. 140216 19:46:16 mysqld_safe Starting mysqld daemon with databases from /Users/gerryyang/LAMP/MySQL/mysql-5.6.16-osx10.7-x86/data  
  7.   
  8. root@mba:mysql-5.6.16-osx10.7-x86#ps aux | grep mysql | grep -v grep  
  9. _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  
  10. root             8679   0.0  0.0  2452820   1140 s001  S     7:46下午   0:00.03 /bin/sh bin/mysqld_safe  
  11. root@mba:mysql-5.6.16-osx10.7-x86#  

(4) 使用kill -9 pid干掉MySQL,这里要先把mysqld_safe进程干掉,然后再把mysql进程干掉,否则mysql会被重新拉起
[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. root@mba:mysql-5.6.16-osx10.7-x86#kill -9 8679  
  2. root@mba:mysql-5.6.16-osx10.7-x86#ps aux | grep mysql | grep -v grep  
  3. _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  
  4. [1]+  Killed: 9               bin/mysqld_safe  
  5. root@mba:mysql-5.6.16-osx10.7-x86#kill -9 8757  
  6. root@mba:mysql-5.6.16-osx10.7-x86#ps aux | grep mysql | grep -v grep  
  7. root@mba:mysql-5.6.16-osx10.7-x86#bin/mysql  
  8. 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 
[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. gerryyang@mba:~$whoami  
  2. gerryyang  
  3. gerryyang@mba:~$mysql  
  4. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  5. Your MySQL connection id is 1  
  6. Server version: 5.6.16 MySQL Community Server (GPL)  
  7.   
  8. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.  
  9.   
  10. Oracle is a registered trademark of Oracle Corporation and/or its  
  11. affiliates. Other names may be trademarks of their respective  
  12. owners.  
  13.   
  14. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  15.   
  16. mysql> show databases;  
  17. +--------------------+  
  18. | Database           |  
  19. +--------------------+  
  20. | information_schema |  
  21. | test               |  
  22. +--------------------+  
  23. 2 rows in set (0.00 sec)  
  24.   
  25. mysql> \q  
  26. Bye  
  27. gerryyang@mba:~$su root  
  28. Password:  
  29. root@mba:gerryyang#mysql  
  30. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  31. Your MySQL connection id is 2  
  32. Server version: 5.6.16 MySQL Community Server (GPL)  
  33.   
  34. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.  
  35.   
  36. Oracle is a registered trademark of Oracle Corporation and/or its  
  37. affiliates. Other names may be trademarks of their respective  
  38. owners.  
  39.   
  40. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  41.   
  42. mysql> show databases;  
  43. +--------------------+  
  44. | Database           |  
  45. +--------------------+  
  46. | information_schema |  
  47. | mysql              |  
  48. | performance_schema |  
  49. | test               |  
  50. +--------------------+  
  51. 4 rows in set (0.10 sec)  
  52.   
  53. mysql> use mysql  
  54. Reading table information for completion of table and column names  
  55. You can turn off this feature to get a quicker startup with -A  
  56.   
  57. Database changed  
  58. mysql> show tables;  
  59. +---------------------------+  
  60. | Tables_in_mysql           |  
  61. +---------------------------+  
  62. | columns_priv              |  
  63. | db                        |  
  64. | event                     |  
  65. | func                      |  
  66. | general_log               |  
  67. | help_category             |  
  68. | help_keyword              |  
  69. | help_relation             |  
  70. | help_topic                |  
  71. | innodb_index_stats        |  
  72. | innodb_table_stats        |  
  73. | ndb_binlog_index          |  
  74. | plugin                    |  
  75. | proc                      |  
  76. | procs_priv                |  
  77. | proxies_priv              |  
  78. | servers                   |  
  79. | slave_master_info         |  
  80. | slave_relay_log_info      |  
  81. | slave_worker_info         |  
  82. | slow_log                  |  
  83. | tables_priv               |  
  84. | time_zone                 |  
  85. | time_zone_leap_second     |  
  86. | time_zone_name            |  
  87. | time_zone_transition      |  
  88. | time_zone_transition_type |  
  89. | user                      |  
  90. +---------------------------+  
  91. 28 rows in set (0.00 sec)  
  92.   
  93. mysql> select distinct Host, User, Password from user;  
  94. +-----------+------+----------+  
  95. | Host      | User | Password |  
  96. +-----------+------+----------+  
  97. | localhost | root |          |  
  98. | mba.local | root |          |  
  99. | 127.0.0.1 | root |          |  
  100. | ::1       | root |          |  
  101. | localhost |      |          |  
  102. | mba.local |      |          |  
  103. +-----------+------+----------+  
  104. 6 rows in set (0.00 sec)  
  105.   
  106. mysql> select count(1) from user;  
  107. +----------+  
  108. | count(1) |  
  109. +----------+  
  110. |        6 |  
  111. +----------+  
  112. 1 row in set (0.00 sec)  
  113. mysql> select version();  
  114. +-----------+  
  115. | version() |  
  116. +-----------+  
  117. | 5.6.16    |  
  118. +-----------+  
  119. 1 row in set (0.00 sec)  

2 参考

[1] http://blog.microsuncn.com/?p=3604 (在Mac下如何创建用户)


from:http://blog.csdn.net/delphiwcdj/article/details/19297283

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值