今までMAMPを使っていたのですが,macのApacheで同じことをやろうと思っています.
しかし,うまくいかなかったのでどうすればいいか教えてほしいです.
やったことは以下の通りです.
まず,
Macでmysqlを扱う方法
の方法でMySQLを入れて
$ mysql.server start
でMySQLを起動しました.
次に
MacでApacheを立ち上げてみる
を参考に,
$ sudo apachectl start
でapacheを起動しました.
ブラウザのURL入力欄に 127.0.0.1/test.php
と入力し,開くとエラーが出ました.
PHPソース
PHP
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="utf-8"> 5 <title>no title</title> 6</head> 7<body> 8 <?php 9 ini_set('display_errors',1); // エラー表示 10 11 $link = mysqli_connect("127.0.0.1", "root", "", "test"); // データベース名 test 12 13 $query = "SELECT * FROM test;"; // テーブル名 test 14 $result = mysqli_query($link, $query); 15 16 echo "<table>"; 17 echo "<tr bgcolor=#87cefa> 18 <th>データ1</th> 19 <th>データ2</th> 20 </tr>"; 21 22 while( $row = mysqli_fetch_assoc($result) ){ 23 echo "<tr> 24 <td>{$row['data1']}</td> 25 <td>{$row['data2']}</td> 26 </tr>"; 27 } 28 29 echo "</table>"; 30 ?> 31</body> 32</html>
エラー
Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /Library/WebServer/Documents/test.php on line 11 Warning: mysqli_connect(): (HY000/2054): The server requested authentication method unknown to the client in /Library/WebServer/Documents/test.php on line 11 Warning: mysqli_query() expects parameter 1 to be mysqli, bool given in /Library/WebServer/Documents/test.php on line 14 Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /Library/WebServer/Documents/test.php on line 22
追記(2020/03/22)
各バージョン
phpinfo(); より
Apache Version:Apache/2.4.41 (Unix) PHP/7.3.11
Apache API Version:20120211
$ mysql --version
mysql Ver 8.0.18 for osx10.15 on x86_64 (Homebrew)