I use ! @ # $ in my MySQL user’s password

but when using these characters in my password, PDO can’t connect to MySQL server

$servername = "localhost";
$username = "test";
$password = "[email protected]#$test";
$dbname = "test";

try {
  $test = $_POST['test'];
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, 
  $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
  // set the PDO error mode to exception

  // prepare sql and bind parameters
  $stmt = $conn->prepare("INSERT INTO test (test) 
  VALUES (:test)");
  $stmt->bindParam(':test', $test);


It gives this error:

SQLSTATE[HY000] [1045] Access denied for user ‘test’@’localhost’ (using password: YES)

when removing [email protected]#$ from password it works correctly