提示のエラーコード原文ですがそのエラーが発生してまうのですが対象方法が知りたいです。mysql
のデータベースにはBulletin_Board
というデータベースがあります。これはどうやって対処すればいいのでしょうか?試したこと部のようにいろいろ実験しましたがエラーコードの変化が現れず対処できません。
環境
centOS
さくらvps
試したこと
1,'$dsn = 'mysql:dbname=Bulletin_Board;host=xxxxx.vs.sakura.ne.jp;charset=utf8';'
のホスト名をIPアドレスに変更
2,下記のようにmysqlでデーターベースを設定
MariaDB [Bulletin_Board]> select database();
+----------------+
| database() |
+----------------+
| Bulletin_Board |
+----------------+
3,下記のコマンドを実行
CREATE USER 'root'@'ホスト名' IDENTIFIED BY 'password';
>GRANT ALL PRIVILEGES ON laravelDB.* TO 'root'@'ホスト名'
エラー原文
SQLSTATE[HY000] [1044] Access denied for user 'root'@'xxx.xx.xxx.xxx' to database 'Bulletin_Board'
参考サイト: https://shiro-changelife.com/laravel-access-denied/
参考サイト: https://watsunblog.com/rootlocalhost-error/
参考サイト: https://zero-lara.com/2021/07/22/access-denied-for-user-root-localhost/
参考サイト: https://synboo.hatenablog.com/entry/2012/02/26/220949
php
<!DOCTYPE html>
<html lang=ja>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="style.css">
<title>send</title>
</head>
<body>
<?php
session_cache_limiter('none');
session_start();
session_regenerate_id(true);
ini_set("display_errors",1);
error_reporting(E_ALL);
require_once "dataBase.php";
//echo GetUUID()."<br>";
?>
<!-- ログアウトアイコン -->
<?php if(isset($_SESSION['login']) == true)
{
?>
<!-- ログイン中 -->
<form action="logout.php" method="post">
<button type="submit"> ログアウト </button>
</form>
<form action="newThread.php" method="post">
<button type="submit"> スレッドを立てる </button>
</form>
<form action="profile.php?ID=<?php echo $_SESSION["id"] ?>" method="post">
<button type="submit" name="submit"> プロフィール </button>
</form>
<?php
}
?>
<h1 class="center" > 掲示板 </h1>
<!-- 検索 -->
<form class="center" action="search.php" method="post">
<input type="text" name="name"><br>
<button type="submit" name="submit"> 検 索 </button>
<br>
</form>
<br>
<?php
try
{
$dsn = 'mysql:dbname=Bulletin_Board;host=xxxxx.vs.sakura.ne.jp;charset=utf8';
$dbh = new PDO($dsn,"root","xxx");
$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$sql = 'SELECT * FROM Thread';
$stmt = $dbh->prepare($sql);
$stmt->execute();
}
catch(PDOException $e)
{
die($e->getMessage());
}
?>
<?php if(isset($_SESSION['login']) == false)
{
?>
<form class="center" action="register.php" method="post">
<button type="submit"> 登録 </button>
</form>
<form class="center" action="login.php" method="post">
<button type="submit"> ログイン </button>
</form>
<?php
}
try
{
$dsn = 'mysql:dbname=Bulletin_Board;host=xxxx.vs.sakura.ne.jp;charset=utf8';
$dbh = new PDO($dsn,"root","xxxx");
$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$sql = 'SELECT * FROM Thread ORDER BY post_count DESC';
$stmt = $dbh->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
}
catch(PDOException $e)
{
die($e->getMessage());
}
for($i = 0; $i < $stmt->rowCount(); $i++)
{
?>
<!-- 人気スレッドを表示 -->
<a href="thread.php?title=<?php echo $result[$i]["id"] ?>"> <?php echo $result[$i]["name"] ?> </a>
<?php
if($i == 20)
{
?>
<h1> これ以上表示出来ません検索を利用してください。 </h1>
<?php
break;
}
}
?>
</body>
</html>
mysql
MariaDB [(none)]> select user, host from mysql.user;
+----------------+----------------+
| user | host |
+----------------+----------------+
| Bulletin_Board | % |
| root | % |
| root | xxx.x.x.x |
| root | xxxxxxxxxxxxxx |
| shigurechan | xxxxxxxxxxxxxx |
| root | ::1 |
| root | localhost |
| shigurechan | localhost |
+----------------+----------------+