PHP

PHP MySql 安装 - MAC

2020-04-22  本文已影响0人  887d1fc86fe6
一、安装 Mysql


二、环境变量
$ cd ~
$ vim ./.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
export PATH=$PATH:/usr/local/mysql/support-files
:wq
$ source ~/.bash_profile 
$ echo $PATH
$ mysql -V
开启MySQL服务
sudo mysql.server start

停止MySQL服务
sudo mysql.server stop

重启MySQL服务
sudo mysql.server restart

查看MySQL服务状态
sudo mysql.server status


三、启动 MySql
$ sudo mysql.server start
mysql -u root -p
dengzemiaodeMacBook-Pro:~ dengzemiao$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 466
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
四、初始化设置
set password = password('123456');
dengzemiaodeMacBook-Pro:~ dengzemiao$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 466
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('123456');

回车,然后会提示设置成功。

exit

以上 MySql 就在本地安装完成了,现在我们需要来配置与 PHP 关联起来。



五、PHP 连接 MySql
<?php
  if (mysqli_connect('localhost', 'root', '123456')) {

    echo '连接数据库成功';

  } else {

    echo '连接数据库失败';
  }
?>
mysql -u root -p
STATUS
dengzemiaodeMacBook-Pro:~ dengzemiao$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 276
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> STATUS
mysql  Ver 14.14 Distrib 5.7.28, for macos10.14 (x86_64) using  EditLine wrapper

Connection id:      276
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.28 MySQL Community Server (GPL)
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /tmp/mysql.sock
Uptime:         20 min 2 sec

Threads: 1  Questions: 16  Slow queries: 0  Opens: 105  Flush tables: 1  Open tables: 98  Queries per second avg: 0.013
--------------

mysql> 
UNIX socket:        /tmp/mysql.sock
<?php
  phpinfo();
?>
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket = /tmp/mysql.sock
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysqli.default-socket
mysqli.default_socket = /tmp/mysql.sock
;extension=php_mysqli.dll
上一篇 下一篇

猜你喜欢

热点阅读