OSX下MySQL学习基础环境搭建

1.1下载MySQL5.6.X安装


下载链接:http://dev.mysql.com/downloads/mysql/ 

选择:  Mac OS X 10.7 (x86, 64-bit), DMG Archive

下载后双击打开,按引导进行安装。



1.2 启动数据库服务器


安装完成后运行ps ax|grep mysql 查看下进程:
$ ps ax|grep mysql
 7895 s001  S      0:00.02 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/onion.local.pid
 7993 s001  S      0:00.92 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/onion.local.err --pid-file=/usr/local/mysql/data/onion.local.pid
 8053 s001  S+     0:00.00 grep mysql


判断为mysqld_safe这个脚本运行的mysql主进程mysqld, 所以应该可以用如下命令启动mysql:

/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/onion.local.err --pid-file=/usr/local/mysql/data/onion.local.pid

测试可用。 google查到OSX下另一种启动方式

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start


1.3 启动mysql客户端


找到MySQL官方教程: http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html#connecting-disconnecting

启动客户端,终端下执行 (需要使用root登录,否则后面建立数据库时会有权限问题):

mysql -u root -p


1.4 建立数据库test


mysql> CREATE DATABASE test;
ERROR 1007 (HY000): Can't create database 'test'; database exists

原因:系统已经自带了test数据库:


mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)


建立数据库test1:

mysql> CREATE DATABASE test1;
Query OK, 1 row affected (0.01 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| test1              |
+--------------------+
5 rows in set (0.00 sec)



最近我在Dataguru学了《MySQL数据库查询优化》网络课程,挺不错的,你可以来看看!要是想报名,可以用我的优惠码 NH15,立减你50%的固定学费!

bsknight分享了炼数成金邀请码,使用邀请码报名课程可以减免50%固定学费哦!
http://www.dataguru.cn/invite.php?invitecode=NH15




你可能感兴趣的:(OSX下MySQL学习基础环境搭建)