您的位置:首页 > 数据库 > MySQL

mac安装MySQL

2015-10-25 00:10 597 查看
一、在官网http://dev.mysql.com/downloads/链接中选择对应Mac OS X系统的MySQL的版本:MySQL Community Server (GPL),在下载页面提供有两种格式的文件下载,一种为tar.gz格式,另一种为dmg格式,这里推荐dmg格式。

补充:

(1)官网中提供的有enterprise企业版本下载,这里请选择community社区版本下载。

(2)这里解释下为什么下载dmg版本:在官网文档中,tar.gz格式和dmg格式的安装方式不同,原文如下

MySQL for OS X is available in a number of different forms:

• Native Package Installer, which uses the native OS X installer (DMG) to walk you through the installation of MySQL. For more information, see Section 2.4.2, “Installing MySQL on OS X Using Native Packages”. You can use the package installer with OS X. The
user you use to perform the installation must have administrator privileges.

• Compressed TAR archive, which uses a file packaged using the Unix tar and gzip commands. To use this method, you will need to open a Terminal window. You do not need administrator privileges using this method, as you can install the MySQL server anywhere
using this method.

选择tar.gz格式的话安装步骤会繁琐些,详见http://dev.mysql.com/doc/refman/5.6/en/binary-installation.html

二、在Finder中双击打开dmg后,会出现pkg文件,继续双击安装,这里需要说明的是在安装过程中,不需要改动任何设置,全部保持默认即可。

补充:

也许会有疑问,在windows中安装时,至少得选择数据库的编码和设置root用户密码吧,这里怎么都没有,其实在Mac中会和windows有些不同,上面说的说有操作是在安装后再设置的(在本文后续中会有说明),在安装过程中并没有提供相关设置。

三、安装后,在Mac系统设置,也即system preferences中会出现MySQL的标志,如下图所示,



点击打开后如下所示



在其中可以

(1)启动/关闭MySQL服务

(2)设置MySQL是否开机自动启动。

四、到这里为止,MySQL其实已经安装成功了,可以在terminal终端中使用MySQL自带的bin命令使用MySQL了,例如

(1)登陆MySQL服务器

mysql -u root




(2)查看MySQL服务器上有哪些数据库:



(3)指定要使用的数据库



(4)查看该数据库中有哪些表,图中的表是我测试时建的



(5)查询数据表



(6)查看当前数据库服务器中有哪些用户机器密码是什么



从上面可以看出,在localhost服务器上的所有用户root均没有密码,这里可以通过如下方式设置

(7)设置用户密码

mysqladmin -u root password "newpwd"


结果如下



也可以直接使用如下语句,修改mysql.user表(官网说法:You can also use a single statement that assigns a password to all root accounts by using UPDATE to modify the mysql.user table directly. This method works on any platform。)

UPDATE mysql.user SET Password = PASSWORD('newpwd');




(8)修改密码后登陆

mysql -u root -p
按提示输入密码即可。

五、上面的所有操作均是通过terminal完成的,其实,MySQL在Mac下还提供有图形化操作工具MySQL Workbench,官网说明如下(由于比较简单,就直接贴出来了):

MySQL Workbench provides a graphical tool for working with MySQL Servers and databases. MySQL Workbench fully supports MySQL Server versions 5.1 and above. It is also compatible with MySQL Server
5.0, but not every feature of 5.0 may be supported. It does not support MySQL Server versions 4.x.

The following discussion briefly describes MySQL Workbench capabilities. For more information, see the MySQL Workbench manual, available at http://dev.mysql.com/doc/workbench/en/.
MySQL Workbench provides five main areas of functionality:

SQL Development: Enables you to create and manage connections to database servers. As well as enabling you to configure connection parameters, MySQL Workbench provides the capability to execute SQL queries on the database connections using the built-in SQL
Editor. This functionality replaces that previously provided by the Query Browser standalone application.

Data Modeling: Enables you to create models of your database schema graphically, reverse and forward engineer between a schema and a live database, and edit all aspects of your database using the comprehensive Table Editor. The Table Editor provides easy-to-use
facilities for editing Tables, Columns, Indexes, Triggers, Partitioning, Options, Inserts and Privileges, Routines and Views.

Server Administration: Enables you to create and administer server instances.

Data Migration: Allows you to migrate from Microsoft SQL Server, Sybase ASE, SQLite, SQL Anywhere, PostreSQL, and other RDBMS tables, objects and data to MySQL. Migration also supports migrating from earlier versions of MySQL to the latest releases.

MySQL Enterprise Support: Support for Enterprise products such as MySQL Enterprise Backup and MySQL Audit.

MySQL Workbench is available in two editions, the Community Edition and the Commercial Edition. The Community Edition is available free of charge. The Commercial Edition provides additional Enterprise features, such as database documentation generation, at
low cost.

安装方法同MySQL dmg方法,一路next即可。操作界面如下:



在其中可以完成数据库链接,数据库操作ARUD,数据库建模,修改数据库所用字符集(右击数据库选择Alter Schema,在弹出的tab页中修改即可)等,大家尽情摸索吧!

到这里为止,MySQL在Mac上的生产环境已经搭建完毕!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: