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

 

猜你喜欢

转载自taotie119.iteye.com/blog/1972303