Ye Wei's blog

所见、所感、所想


  • 首页

  • 分类

  • 归档

  • 标签

Mac常用命令

发表于 2017-05-15 | 分类于 技术 |

显示系统隐藏文件

运行下面命令

1
2
defaults write com.apple.finder AppleShowAllFiles -bool true  此命令显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles -bool false 此命令关闭显示隐藏

重新加载Finder: command + option + esc, 选中Finder, 即可重新启动

MySQL忘记密码后重置密码( Mac )

发表于 2017-05-15 | 分类于 技术 |

安装好MySQL以后,系统给了个默认的的密码,当时是第一次在Mac上安装,所以忽略了,后来登录MySQL的时候需要用到密码,但不知道密码,所以得修改这个密码了,然后就走上了不归路。

这个过程是心酸的,网上的资料多如狗,关键是各有各的错法,尝试了半天没一个对的,在即将打破心理防线,要去翻MySQL文档的时候,成功了有没有。没有一个文章告诉我完整的答案,我是参考了好几个攻略,闭门造出来的车。给自己点赞。不多说了,一步一步跟我

  • 走关闭MySQL服务器
1
sudo /usr/local/mysql/support-files/mysql.server stop

或者在偏好设置里点击MySQL然后将其关闭

  • 进入MySQL的二进制命令目录下
1
cd /usr/local/mysql/bin
  • 获取MySQL操作权限
1
sudo su
  • 重启MySQL服务器

    1
    ./mysqld_safe --skip-grant-tables
  • 重开个终端


  • 为了在终端可以使用MySQL的命令,需要配置一下,运行下面两条命令
1
2
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladminx

使用这种方法进行配置,一旦终端关闭了,就又得重新配置了,最好的方法是将MySQL的bin目录加入系统PATH,我用的终端是zsh,所以讲命令配置在.zshrc,如果是其他终端,修改的是相应的文件( 例如:bash -> ./.bashrc )

打开.zshrc, 添加

1
export PATH=$PATH:/usr/local/mysql/bin

执行命令

1
source ./.zshrc

输入mysql 进入mysql命令模式

输入use mysql 进入mysql数据库

输入flush privileges 获取修改密码的权限

输入set password for ‘root’@’localhost’=password(‘新密码’) 修改密码

恭喜你,密码修改成功

使用新密码登录

1
mysql -u root -p

回车后输入新密码

出现上面这个就说明成功登录MySQL

Mac 生成 ssh-key

发表于 2017-04-13 | 分类于 技术 |

用Git下载代码得步骤
1.首先需要创建公钥,在命令行中输入:

1
ssh-keygen -t rsa -C "ben@xxx.com"

然后输入路径,密码之类的,如果不输入,工程就会保存到根目录下面,密码也为空。

1
~/.ssh/id_rsa是私钥,~/.ssh/id_rsa.pub是公钥

2.接着打开公钥:

1
cat ~/.ssh/id_rsa.pub

这里会得到一段很长的编码:

1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuYZIchz3THIcc/wH0ZB5WZYqe2iBVUNqSzfrgxBvJCZkFHWiUZhA/4omNud/27PVT/FADV9qSvrX7ifP05Cbl6mhE4uJjxOQRNoPdQQcsTEFh5vDvOeiJOT1CoFb9WLGg49Xml4yJmFJqv/Kz5hCe7LEWRYJH6tmaVG0qi9nwAZmjfTQpSWu07eAKB9wAbK6stCdnd5JvMq7IsNNylbwDlXf0RQA4RpppO+14oNBqivhi5ftBPjP15+aWKpnXUxkGMVAefKTvwsyw1T0H2sj+ILVFM4d5xpxu3jPHebqh363OwPPLMsoUy9VhQ3YDtMxt4vyOxvpJ9ekMGlDn/9ut linwenbang@yolanda.hk

然后在进入GitLab或者Gitblit的个人中心,选择ssh key的配置,将新生成的ssh-key复制进去即可,配置完成之后即可克隆你想要克隆的项目了

Hexo+Github,搭建属于自己的博客

发表于 2017-04-01 | 分类于 Blog |

配置环境

安装node( 必须 )

作用:用来生成静态页面的 到Node.js官网下载相应平台的最新版本,一路安装即可。

安装git( 必须 )

作用:把本地的hexo内容提交到github上去. 安装Xcode就自带有Git

申请github( 必须 )

作用:是用来做博客的远程创库、域名、服务器之类的,怎么与本地hexo建立连接等下讲。 github账号我也不再啰嗦了,没有的话直接申请就行了,跟一般的注册账号差不多,SSH Keys,看你自己了,可以不配制,不配置的话以后每次对自己的博客有改动提交的时候就要手动输入账号密码,配置了就不需要了,怎么配置我就不多说了,网上有很多教程。

正式安装HEXO

Node和Git都安装好后,可执行如下命令安装hexo

1
sudo npm install -g hexo

初始化

创建一个文件夹,如:Blog,cd到Blog里执行hexo init的。命令

1
hexo init

生成静态页面

继续再Blog目录下执行如下命令,生成静态页面

1
hexo generate (hexo g)

本地启动

启动本地服务,进行文章预览调试,命令

1
hexo server

Mac上设置MySQL默认编码为UTF-8

发表于 2017-03-23 | 分类于 技术 |
  1. 登录mysql终端,然后输入下面内容,查看该数据库连接使用的字符集的情况
1
show variables like '%char%';
  1. 进入到 /usr/local/mysql/support-files 目录,可以看到里面有个文件: my-default.cnf
  2. 将其复制到桌面上,改名为 my.cnf. 用你喜欢的编辑器将内容替换为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
default-character-set=utf8
#password = your_password
port = 3306
socket = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id = 1

# Uncomment the following if you want to log updates
#log-bin=mysql-bin

# binary logging format - mixed recommended
#binlog_format=mixed

# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout
  1. 将修改后的文件 my.cnf 复制到 /etc 目录下
  2. 重启mysql

在Macbook Pro配置Apache + PHP + MySQL开发环境以及MySql的简单使用

发表于 2017-03-12 | 分类于 技术 |

启动Apache

  1. Mac OS自带Apache, 只需要启动Apache就可以了
1
sudo apachectl start

介绍另外几个命令

1
2
3
sudo apachectl restart //重启Apache服务
sudo apachectl stop //停止Apache服务
httpd -v //查看Apache版本
  1. 打开浏览器,在地址栏输入localhost, 出现It Works, 就说明已经成功启动

  1. 进入Apache的网站服务器根目录
1
cd /Library/WebServer/Documents
  1. Mac OS 同样自带PHP,只需要在Apache的配置文件中添加Apache对PHP的支持就好了
1
2
3
sudo vim /etc/apache2/httpd.conf //打开文件

#LoadModule php5_module libexec/apache2/libphp5.so //去掉注释(前面的 # 号)
  1. 重启Apache服务器
  2. 在/Library/WebServer/Documents下新建php文件,例如test.php
  3. 在浏览器中输入 localhost/test.php, 如果出现预期的结果,恭喜你!

MySQL

  • 启动MySQL的安全模式,可以免登录名和密码
1
sudo mysqld --skip-grant-tables
  • 使用root用户[免密码]登录MySQL
1
2
3
mysql -u root -p

输入密码时直接回车
  • 解决MAC下PHP连接MYSQL错误Warning: mysql_connect(): No such file or directory in conn.php
1
2
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
12
Ye Wei

Ye Wei

一名懒惰的Coder兼理想主义者。懒惰 -「驱使你极力努力以减少精力的总的消耗的美德」

16 日志
3 分类
13 标签
RSS
GitHub 微博
© 2017 - 2018 Ye Wei
由 Hexo 强力驱动
主题 - NexT.Pisces