分类目录归档:MAC

1、brew install mysql
2、brew services start mysql
3、mysql_secure_installation

cometdeMacBook-Pro:~ comet$ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N   // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
Please set the password for root here.

New password:            // 设置密码

Re-enter new password:     // 再一次确认密码
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

设置远程访问:
1、mysql -u root -p

2、grant all privileges on . to 'root'@'%' identified by '123456' with grant option;

flush privileges;

3、打开 /usr/local/Cellar/mysql/5.7.16/下的homebrew.mxcl.mysql.plist文件,去掉

<string>--bind-address=127.0.0.1</string>

4、brew services stop mysql

brew services start mysql

Mac OS X下安装pyenv

Pyenv是python的版本管理工具,pyenv之于python相当于rvm之于ruby。

在Mac OS X下,我用homebrew安装pyenv:

brew update
brew install pyenv

安装过程中,遇到了下面这个问题

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

直接安装openssl好像不管用,Google上搜了一下,在pyenv issue #263下找到了解决方法,运行

xcode-select --install

安装一下Xcode Command Line tools,再重新运行一下pyenv的安装命令就好了。

安装好pyenv后,会有以下提示

==> Caveats
To enable shims and autocompletion add to your profile:
  if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

To use Homebrew's directories rather than ~/.pyenv add to your profile:
  export PYENV_ROOT=/usr/local/opt/pyenv

按照提示,将以上的两条语句添加到profile里就可以了,由于我用的shell是zsh,所以我在.zshrc里追加

export PYENV_ROOT=/usr/local/opt/pyenv
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

这里要注意,这两个语句的顺序不能颠倒,不然"pyenv global/local"将不起作用。

要使改变马上生效,运行一下

$SHELL -l

至此,pyenv的配置也完成了。

现在,我们可以查看一下可安装的python版本

pyenv install -l

选好要安装的版本后,运行下面这条命令安装

pyenv install <version>

安装完成之后需要对数据库进行更新:

pyenv rehash

我们可以用pyenv versions查看已安装的版本,要切换python版本,可以用

pyenv global/local <version>

运行global命令会切换全局的python版本;

而local命令则会在当前目录下创建.python_version,管理当前目录及其子目录(子目录没有.python_version的情况下)的python版本。

通常,我们在项目目录下设置一下local版本就可以了,原因如下

一般的,我们不修改全局版本,而使用期默认值system,因为在unix系统上,很多系统工具依赖于Python,如果我们修改了Python的版本,会造成绝大多数的依赖Python的系统工具无法使用,如果你不小心修改了,也不要紧张,使用global命令修改回来就可以了,有时候,你发现部分系统工具无法使用,你也可以看看你当前的Python版本。

参考

https://github.com/yyuu/pyenv#homebrew-on-mac-os-x

https://github.com/yyuu/pyenv/issues/263

https://github.com/yyuu/pyenv/blob/master/COMMANDS.md#pyenv-install

https://github.com/lixm/pybooklet/blob/master/install.md

http://seisman.info/python-pyenv.html

http://v2in.com/pyenv-installation-and-usage.html

 

MAC安装PIL

开始使用如下命令:

pip install pil

报如下错误

Collecting pil
  Could not find a version that satisfies the requirement pil (from versions: )
  Some externally hosted files were ignored as access to them may be unreliable (use --allow-external pil to allow).
No matching distribution found for pil

后来查了解决办法:见http://stackoverflow.com/questions/19532125/cant-install-pil-after-mac-os-x-10-9

使用如下步骤

pip install Pillow
ln -s ../Cellar/freetype/2.6_1/include/freetype2 freetype
pip install pil --allow-external pil --allow-unverified pil
pip install Pillow

成功安装

 

MAC 10.11 OSX EI Brew安装环境问题汇总

  1. 权限问题

全部格掉重装的EI Capitan,然后把开发的代码再COPY过来,问题如下

drwxrwxrwx@  47 Ben  staff      1598 10 16 16:08 Dashboard

这个目录的权限和用户组全部对的,但是phpstorm编辑器打开这个目录,就是无法生成配置.idea的文件

一直报

Unable to save settings: Failed to save settings. Please restart PhpStorm

这个错误,我手动重新指定用户组,再手动改权限

chown -R Ben:staff Dashboard

chmod -R 777 Dashboard

    解决办法:
chmod -R -a "group:everyone deny add_file,delete,add_subdirectory,delete_child,writeattr,writeextattr,chown" "Users/myusername"

通过上上命令来修改权限

2. Mysql问题

Mysql 安装后无法link,执行"brew docker"报如下问题:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/man/man8/mysqld.8
/usr/local/share/man/man8 is not writable.

执行好事命令解决问题:

sudo chown -R `whoami` /usr/local

Mac下ssh使用密钥登录

putty可以使用ppk格式的私钥通过ssh登录主机,而不需要输入密码
Mac下,如何使用得到的ppk?

1. 安装putty

brew install putty

2. 使用puttygen生成.pem格式密钥

puttygen privatekey.ppk -O private-openssh -o privatekey.pem

3. 直接使用密钥登录

ssh -i privatekey.pem user@my.server.com

 

Mac OSX中Apache启动报AH00016: Configuration Failed解决办法

今天系统更新,更新完后Apache无法启动,查看日志中一大堆

AH00016: Configuration Failed

网上找了半天没找到解决办法,又查了好多相关内容,终于发现问题是:

Too many open files

导致,这样一来就好解决了, 方法如下:

sudo launchctl limit maxfiles 1000000 1000000
#查看修改是否成功
sysctl -a | grep files

mac osx中通过homebrew安装的libpng升级后apache报错的解决办法

升级libpng到1.6版本后,重启apache的时候报如下错误:

httpd: Syntax error on line 119 of /private/etc/apache2/httpd.conf: Cannot load /usr/local/opt/php53/libexec/apache2/libphp5.so into server: dlopen(/usr/local/opt/php53/libexec/apache2/libphp5.so, 10): Library not loaded: /usr/local/lib/libpng15.15.dylib\n  Referenced from: /usr/local/opt/php53/libexec/apache2/libphp5.so\n  Reason: image not found

解决办法:

cp /usr/local/Cellar/libpng/1.5.18/lib/libpng15.15.dylib /usr/local/lib/libpng15.15.dylib

升级MAC OX上的Python到3.4版本

1. 下载最新的python3.4
下载Mac OS X 64-bit/32-bit installer
https://www.python.org/downloads/release/python-340/

2.安装DMG文件
安装下载的dmg文件

3. 配置

#!/bin/bash
#python版号需要修改两个地方
#1. new_version

#sudo -i #得到超级权限
new_version="3.4"

PYPATH=/System/Library/Frameworks/Python.framework/Versions/"$new_version"
#第1步移动新版python到mac默认目录下
echo "move.."
mv /Library/Frameworks/Python.framework/Versions/"$new_version" /System/Library/Frameworks/Python.framework/Versions/
#第2步改变用户目录的用户组
echo "chown.."
chown -R root:wheel ${PYPATH}
#第3步 删除原来2.7的链接
echo "del.."
rm /System/Library/Frameworks/Python.framework/Versions/Current
#第4步重新链接到最新版本的python
echo "ln.."
ln -s ${PYPATH} /System/Library/Frameworks/Python.framework/Versions/Current
#第5步删除旧的命令符号链接
echo "rm.."
rm /usr/bin/{pydoc,python,pythonw,python-config}
echo "ln bin.."
#第6步重新建立新的命令符号链接
ln -s ${PYPATH}/bin/pydoc"$new_version" /usr/bin/pydoc
ln -s ${PYPATH}/bin/python"$new_version" /usr/bin/python
ln -s ${PYPATH}/bin/pythonw"$new_version" /usr/bin/pythonw
ln -s ${PYPATH}/bin/python"$new_version"m-config /usr/bin/python-config


python_param_list=`cd /usr/local/bin && ls -al |grep "Python"|awk 'ORS=" " {print $9}'`
#第7步修复其他链接
for i in $python_param_list;do
  echo "info: $i"
  rm -f /usr/local/bin/${i}
  ln -sv /System/Library/Frameworks/Python.framework/Versions/"$new_version"/bin/${i} /usr/local/bin/${i}
done

#第8步.环境变量要修改为最新的版本号
echo 'export PATH=/System/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}' >> ~/.bashrc

exit #退出超级权限