mac mysql 忘记初始密码

  1. 停止MySQL服务
sudo /usr/local/mysql/support-files/mysql.server stop
  1. 禁止mysql验证功能(先获取管理员权限)
cd /usr/local/mysql/bin/
sudo su
./mysqld_safe --skip-grant-tables &

上述步骤后mysql会自动重启

  1. 进入mysql重设密码
./mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1234';

mysqli代替mysql

<?PHP 
$dbhost="127.0.0.1";
$dbport="3306";
$dbuser="root";
$dbpass="1234";
$dbname="menghaozi";
if(!function_exists('mysql_pconnect')){
    $mysqli = mysqli_connect("$dbhost:$dbport", $dbuser, $dbpass, $dbname);
    function mysql_pconnect($dbhost, $dbuser, $dbpass){
        global $dbport;
        global $dbname;
        global $mysqli;
        $mysqli = mysqli_connect("$dbhost:$dbport", $dbuser, $dbpass, $dbname);
        return $mysqli;
        }
    function mysql_select_db($dbname){
        global $mysqli;
        return mysqli_select_db($mysqli,$dbname);
        }
    function mysql_fetch_array($result){
        return mysqli_fetch_array($result);
        }
    function mysql_fetch_assoc($result){
        return mysqli_fetch_assoc($result);
        }
    function mysql_fetch_row($result){
        return mysqli_fetch_row($result);
        }
    function mysql_query($query){
        global $mysqli;
        $data=mysqli_query($mysqli,$query);
        if (!$data) {
         printf("Error: %s\n", mysqli_error($mysqli));
         exit();
        }
        return $data;
        }
    function mysql_escape_string($data){
        global $mysqli;
        return mysqli_real_escape_string($mysqli, $data);
        //return addslashes(trim($data));
        }
    function mysql_real_escape_string($data){
        return mysql_real_escape_string($data);
        }
    function mysql_close(){
        global $mysqli;
        return mysqli_close($mysqli);
        }
}
?>

mac配置

初始不设置磁盘加密
显示隐藏文件

defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder

不显示隐藏文件

defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder

Mac基本快捷键

space:预览
command+w:关闭
command+q:退出
command+z:撤销
command+shift+z:重做
command+x:剪切
command+c:复制
command+v:粘贴
command+a:全选
command+r:刷新
command+s:保存
command+f:查找
command+space:切换输入法
command+tab:程序切换
command+~:同程序窗口切换
command++:放大
command+—:缩小
command+h:隐藏当前窗口
command+alt+f:隐藏除当前窗口外其他窗口
command+delete:删除
command+shift+delete:清空废纸篓
fn+command+delete:删除后面
command+方向键:光标跳到文本行的首位和文件的首位
command+F3:显示桌面
command+n:打开新窗口
command+m:最小化窗口
command+o:打开文件
command+ctrl+f:全屏
command+shift+3:截取全屏(+alt保存到剪切版)
command+shift+4:截取部分屏幕(按住space空格键选取窗口+alt保存到剪切版)
command+alt+esc:强制退出程序
按住command可以多选文件
开机alt选择启动驱动
control+shift+电源:关闭显示器
command+alt+电源:睡眠
command+control+电源:重启

触控板快捷方式-系统偏好设置-触控板有演示(滚动方向-自然不勾选)

环境变量设置:终端输入export PATH=/usr/local/php/bin:$PATH 或者在/etc/profile文件最后加入,立即执行环境变量文件source /etc/profile

安装brew

git config --global http.postBuffer 524288000
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

终端:终端iterm2下载 Finder-自定义工具栏-iterm2拖到工具栏上

Git:gitkarken下载

编辑器:macvim下载 macvim放到应用程序下 mvim放到/usr/bin/下

vim中文帮助:vimdoc下载 根目录sudo ./vimcdoc.sh -i

更多vim配置

ftp:filezilla客户端下载

数据库:mysql下载 安装后系统偏好设置有个Mysql图标,可以启动Mysql服务。

mysql配置:/usr/local/mysql/为maysql目录
设置mysql不需要密码,经常出错没有root密码,干脆不要密码,等创建完用户记得删掉,个人电脑就无所谓了,要密码还麻烦。

sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
sudo vi /etc/my.cnf
#[mysqld]下添加
skip-grant-tables
#esc :wq!

apache:mac自带了apache,不需要安装,看了下版本是2.4.16,官方是2.4.20,还可以。apache服务的目录/etc/httpdctl或者/usr/sbin/httpd,模块目录/usr/libexec/apache2/,配置文件目录/etc/apache2/。启动服务:sudo apachectl start

安装php:php下载

#扩展openssl gd mbstring
./configure --prefix=/usr/local/php --with-apxs2=/usr/sbin/apxs --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
make
make install
sudo cp php.ini-development /usr/local/php/lib/php.ini

配置apache

sudo vi /etc/apache2/httpd.conf
#查找字符串AddType,并增加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#查找字符串
DirectoryIndex
#并修改为
DirectoryIndex index.html index.php default.php
#将#LoadModule rewrite_module libexec/apache2/mod_rewrite.so的#删除
#AllowOverride None 改 AllowOverride All

php扩展安装

phpize

m4下载 autoconf下载
先编译安装m4然后编译安装autoconf

./configure
make
make install

或者使用brew

brew install homebrew/dupes/m4
brew install autoconf

扩展openssl

#进入到目录etc/openssl
export PATH=/usr/local/php/bin/:$PATH
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

php.ini加extension =openssl.so
重启apache
mongodb安装

#mongodb安装
brew install mongodb --with-openssl
#mongodb设置开机启动
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
#mongod服务启动
mongod --config /usr/local/etc/mongod.conf

node安装:

brew install node

redis安装

#redis安装
brew install redis
#redis设置开机启动
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
#redis服务启动
redis-server /usr/local/etc/redis.conf

supervisor安装

npm install supervisor -g

php不识别imagecreate()

没有gd,编译php扩展gd。
php.ini添加extension = gd.so

如果提示没有png.h则安装libpng:brew install libpng

php不识别imagettftext

安装freetype再重新编译gd:freetype下载

./configure --prefix=/usr/local/freetype
make
sudo make install
#编译freetype过程中以下harfbuss没有则安装
#  external zlib: yes (pkg-config)
#  bzip2:         yes (autoconf test)
#  libpng:        yes (pkg-config)
#  harfbuzz:      no  (pkg-config)
brew install harfbuzz

进入到php/ext/gd/

make clean
#重新编译GD之前一定要make clean就是因为忘记了这个找个半天错误。
phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-freetype-dir=/usr/local/freetype
make
sudo make install

php不识别imagecreatefromjpeg

安装jpegsrc再重新编译gd:jpegsrc下载

./configure --prefix=/usr/local/jpeg
make
sudo make install

进入到php/ext/gd/

make clean
phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype
make
sudo make install

linux系统mysql

grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘密码’;

权限:select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file

所有权限:all privileges或者all

所有数据库所有表:*.*

所有地址:’%’

grant all privileges on *.* to root@'%' identified by 'password'