`

Mac系统中使用MacPorts安装MySQL

 
阅读更多

1.安装MacPorts

MacPorts前称DarwinPorts,是一个软件包管理系统,用来简化Mac OS X和Darwin操作系统上软件的安装。

http://www.macports.org/install.php

到这个网站下载MacPorts,并安装

 

2.使用Mac安装MySQL

sudo port -v install mysql5-server mysql5

如果安装成功,会有以下输出:

...
If this is a new install, in order to setup the database you might want to run:
sudo -u _mysql mysql_install_db5

--->  Cleaning mysql5-server
--->  Removing work directory for mysql5-server
--->  Computing dependencies for mysql5.
--->  Cleaning mysql5
--->  Removing work directory for mysql5
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.

  

有时,可能会遇到以下错误:

configure: error: C compiler cannot create executables

 这个错误是由于没有安装c编译器造成的,可以在xcode中安装

Preferences->Downloads->Components

 

2.1 初始化数据库

 

sudo -u _mysql mysql_install_db5
 执行成功有以下输出:

 

 

xxxx-MacBook-Pro:MHLogin strider$ sudo -u _mysql mysql_install_db5
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h wmbs-MacBook-Pro.local password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!
 注意MySQL安装到了什么地方。

 

 

启动MySQL

 

sudo mysqld_safe5
 

 

 

131104 19:39:18 mysqld_safe Logging to '/opt/local/var/db/mysql5/wmbs-MacBook-Pro.local.err'.
131104 19:39:18 mysqld_safe Starting mysqld daemon with databases from /opt/local/var/db/mysql5
 Ctrl+z,暂停,之后运行命令

 

 

bg
 是MySQL在后台运行。

 

 

2.2命令行,运行以下命令

 

sudo mysql_secure_installation5
 

 

 

xxxx-MacBook-Pro:~ strider$ sudo mysql_secure_installation5
Password:




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


xxxx-MacBook-Pro:~ strider$ 
 设置root帐户的密码,并且移除test数据库,进行安全设置

 

 

2.3 连接数据数据库

 

sudo mysql5 -uroot -proot

 

可能有以下错误:

sh-3.2# mysql5 -uroot -proot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)

 这是由于没有启动mysql server

可以使用mysqld_safe5,bg启动mysql server,并后台运行

sh-3.2# sudo mysqld_safe5
131104 20:30:10 mysqld_safe Logging to '/opt/local/var/db/mysql5/wmbs-MacBook-Pro.local.err'.
131104 20:30:10 mysqld_safe Starting mysqld daemon with databases from /opt/local/var/db/mysql5
^C^Z
[1]+  Stopped(SIGTSTP)        sudo mysqld_safe5
sh-3.2# bg
[1] sudo mysqld_safe5 &
sh-3.2# mysql5 -uroot -proot

 

3. 安装MySQL-python

如果是做python开发,需要安装MySQL-python

pip install MySQL-python==1.2.3

 安装成功,会有以下输出:

 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /opt/local/lib/libcrypto.dylib
    ld: warning: ignoring file /opt/local/lib/libssl.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /opt/local/lib/libssl.dylib
    
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'ChangeLog'
    warning: no files found matching 'GPL'
Successfully installed MySQL-python
Cleaning up...
(virtualenv)sh-3.2# 

 可能会有以下错误:

EnvironmentError: mysql_config not found

 解决办法:

cd /opt/local/bin
sudo ln -s /opt/local/lib/mysql5/bin/mysql_config .

 注意路径/opt/local/lib/mysql5/bin,根据自己的mysql安装路径相应修改。

 

*注意mysqld_safe5和mysql5后面的数字是使用MacPosts安装MySQL自动加上的,表明MySQL的版本。

 

查看mysql的版本:

mysql> status;

http://www.chenruixuan.com/archives/411.html 

 

mysql 字符集utf8mb4

 

MYSQL 5.5 之前, UTF8 编码只支持1-3个字节,只支持BMP这部分的unicode编码区, BMP是从哪到哪,到 http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters 这里看,基本就是0000~FFFF这一区。 从MYSQL5.5开始,可支持4个字节UTF编码utf8mb4,一个字符最多能有4字节,所以能支持更多的字符集。

http://www.tuicool.com/articles/zAnEV3

 

 

 

 

 

 

 

  • 大小: 82.1 KB
分享到:
评论

相关推荐

    macports手册英文版pdf

    MacPorts是一个强大的工具,它极大地简化了在Mac OS X和其他类Unix系统上管理和安装开源软件的过程。通过遵循本指南中的指导,用户不仅可以高效地安装和管理软件,还可以充分利用MacPorts所提供的各种高级功能。无论...

    MacPorts-2.1.2.tar.gz

    MacPorts是针对苹果Mac OS操作系统的一个开源软件管理工具,它为用户提供了自动化安装、更新和管理各种开源软件包的能力。这个“MacPorts-2.1.2.tar.gz”文件是MacPorts的2.1.2版本,以.tar.gz格式打包,这种格式在...

    macports-2.4.1-10.11 安装包

    macports-2.4.1-10.11 安装包

    MacOSX下安装Nginx+PHP+Mysql.pdf

    在MacOS上安装MySQL,可以下载MySQL的源代码并手动编译安装,也可以使用MacPorts或者Homebrew这样的包管理器来进行安装。例如使用Homebrew的命令brew install mysql就可以完成安装。安装完成后,MySQL的配置文件位于...

    mac上安装kinect

    MacPorts 是一个开源的软件安装工具,用于在 Mac 上安装和管理软件。在安装 Kinect 之前,需要安装 MacPorts。 Libtool Libtool 是一个开源的库管理工具,用于管理和安装软件库。在安装 Kinect 之前,需要安装 ...

    gmt-sar安装教程.docx

    在OS X系统中,可以使用Macports或Fink来安装GMT。 二、安装额外的库 在安装GMT-InSAR之前,需要安装一些额外的库,这些库是GMT-InSAR运行所需的。这些库包括GDAL、PCRE、FFTW3和LAPACK等。在Ubuntu 14.04 LTS系统...

    concurrentlua 1.0.5 for macports 安装包

    首先,确保你已经安装了MacPorts,这是一个强大的包管理工具,能让你轻松地在Mac OS X系统上安装和管理各种开源软件。如果你还没有安装MacPorts,可以访问其官方网站获取安装指南。 接下来,你可以按照以下步骤来...

    MacPorts-2.2.1(10.9)

    MacPorts前称DarwinPorts[1],是一个软件包管理系统,用来简化Mac OS X和Darwin操作系统上软件的安装。它是一个用来简化自由软件/开放源代码软件的安装的自由/开放源代码项目,与Fink和BSD类ports套件的目标和功能...

    MacPorts-2.2.1(10.8)

    MacPorts前称DarwinPorts[1],是一个软件包管理系统,用来简化Mac OS X和Darwin操作系统上软件的安装。它是一个用来简化自由软件/开放源代码软件的安装的自由/开放源代码项目,与Fink和BSD类ports套件的目标和功能...

    MacPorts-2.4.2-10.13-HighSierra.pkg

    MacPorts-2.4.2-10.13-HighSierra.pkg,MacPorts-2.4.2-10.13-HighSierra.pkg,

    macports-fonts:用于系统字体的MacPorts端口文件存储库

    这与默认的MacPorts存储库中提供的字体形成对比,默认的MacPorts存储库仅安装和配置为在X11中使用。 包含的字体 当前,大多数字体属于以下两类之一: 专为代码设计的等宽字体 CJK字体,尤其是日语 只有具有许可...

    MacPorts命令手册参考.pdf

    MacPorts是Mac OS X系统上的一款强大的开源软件管理工具,它允许用户方便地安装、管理和更新各种开源软件。MacPorts源自FreeBSD的port系统,它提供了丰富的软件包库,用户可以通过简单的命令行操作来管理这些软件。...

    MacPorts-2.3.3-10.10-Yosemite.pkg

    官网地址是:https://www.macports.org/install.php,该MacPorts是2.3.3版本的,适用于OS X 10.10系统

    MacPorts-2.6.4-10.14-Mojave.pkg

    MacPorts

    macports-www:MacPorts网站

    MacPorts是一个强大的开源工具,它为Mac OS X用户提供了管理和安装开源软件的便捷途径。MacPorts项目维护着一个丰富的软件仓库,其中包含了数千个预编译的开源软件包,覆盖了开发工具、科学计算、图形界面应用等多个...

    MacPorts-2.4.0-10.11-ElCapitan.pkg

    MacPorts-2.4.0-10.11-ElCapitan.pkg

    MacPorts-2.7.1-10.15-Catalina.pkg

    MacPorts-2.7.1-10.15-Catalina.pkg

    MacPorts:在Mac上轻松安装,升级和卸载开源软件-开源

    MacPorts项目是一个开源社区计划,旨在设计一个易于使用的系统,以在macOS上编译,安装和升级命令行,基于X11或Aqua的开源软件。 新版本不再在这里上传; 请改为访问项目网站www.macports.org。

    MacPorts-2.6.3-10.13-HighSierra.pkg

    Mac升级到10.13后ports也要跟着升级才能用 MacPorts-2.6.3-10.13-HighSierra.pkg

    MacPorts-2.5.4-10.14-Mojave.pkg

    MacPorts-2.5.4-10.14-Mojave.pkg

Global site tag (gtag.js) - Google Analytics