php 警告: mysqli_connect(): (28000/1045): 用户 'username'@'10.2.1.19' 访问被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33053127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:21:28  来源:igfitidea点击:

Warning: mysqli_connect(): (28000/1045): Access denied for user 'username'@'10.2.1.19'

phpmysqlmysqli

提问by FreeDay

Hello i still getting this error...can anyone explain me why is there 10.2.1.19? because in my config db file there is localhostinstead of 10.2.1.19..i tried to type 127.0.0.1instead of localhostbut nothing...still 10.2.1.19

您好,我仍然收到此错误...谁能解释一下为什么会出现10.2.1.19?因为在我的配置数据库文件中有localhost而不是10.2.1.19.. 我试图输入127.0.0.1而不是localhost什么...仍然10.2.1.19

My configdb file:

我的配置数据库文件:

 <?php
 $mysqli=mysqli_connect('127.0.0.1','user','','table') or die(mysqli_error($mysqli));
?>

Thanx for help

感谢帮助

回答by Jitendra Kumar. Balla

Maybe because of User name and password. Pass valid username, password and DB Name

可能是因为用户名和密码。传递有效的用户名、密码和数据库名称

<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

回答by Enrique René

Your code is:

你的代码是:

<?php
 $mysqli=mysqli_connect('127.0.0.1','user','','table') or die(mysqli_error($mysqli));
?>

You must to connect do database before try table

你必须在尝试表之前连接数据库

<?php
 $mysqli=mysqli_connect('127.0.0.1','user','','DATABASE_NAME_HERE') or die(mysqli_error($mysqli));
?>

If this still doesn't work, try to set some password, '123' for example, and try connection again. I recommend you to use mysqli class:

如果这仍然不起作用,请尝试设置一些密码,例如“123”,然后再次尝试连接。我建议你使用 mysqli 类:

$some_variable_name = new mysqli('server_name','user_name','password','database_name');
$some_sql_command = "your SQL without ; at final";
$some_variable_name->query($some_sql_command);
$some_variable_name->close();

Go to php.net manual and see all commands.

转到 php.net 手册并查看所有命令。

I'm not an expert in configs, .ini files and these things, so I can't tell nothing about the modified IP.

我不是配置、.ini 文件和这些方面的专家,所以我对修改后的 IP 一无所知。