gpt4 book ai didi

php - 启用mysql允许php访问使用ubuntu服务器作为web服务器

转载 作者:行者123 更新时间:2023-11-29 03:16:45 25 4
gpt4 key购买 nike

我在我的机器上使用 LEMP(Ubuntu Linux 服务器、Nginx、Mysql、PHP)

我已按照本教程进行设置 https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04

我可以使用命令行访问 mysql (mysql -u user -p)

但是如果我在命令行中运行 php 文件,或者在浏览器中加载它,我会收到以下错误

在命令行中运行文件

php index.php
PHP Notice: PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user
'my_username'@'localhost' (using password: YES) in index.php on line 13

PHP代码

$localhost = "localhost";
$username = "my_username";
$pass = "my_password";
$database = "my_database";
$con = mysqli_connect($localhost, $username, $pass, $database) or die("not
connect". mysqli_connect_error());

这个答案并没有真正帮助我 MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)我认为我的问题是我需要启用 mysql 以某种方式允许 php 通信?

最佳答案

拒绝访问错误可能有多种原因。通常问题与 MySQL 帐户有关。

在这种情况下,如果您有一个声明为 $pass = "pas$w"的变量,您将收到一条 E_NOTICE。 undefined variable :w。但是像“pas$w”这样声明就可以了。

MySQL 5.7(替换为您的 mysql 版本)MySQL Docs描述您可以采取的一些行动方案来解决问题。

关于php - 启用mysql允许php访问使用ubuntu服务器作为web服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54617524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com