将PHP连接到MariaDB数据库时出错

I am trying to create a simple web app that prints out database info from MariaDB/MySQL using PHP, im not even at that stage yet... I have trouble when connecting to the database and get the following error:

Host '10.155.237.62' is not allowed to connect to this MariaDB server

Now, I have not done a secure installation so my Mariadb Server allows access from wildcard host and infact any host.I have also tried the code with the root account but received the same error. Can anyone tell me if its my code or whether its a procedure im not aware of that disallows connectors to access the information?

Here is my code:

<?php
$con=mysqli_connect("vm-007.server.com","testuser","testpass","my_db");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MariaDB: " . mysqli_connect_error();
  }
?>

Thanks in advance!

3个回答



我将从远程机器的命令行测试你的mysql数据库访问</ p>

mysql -h vm -007.server.com -u testuser my_db -p </ p>

它将要求您输入密码并输入密码。</ p>

如果失败则 你可能正在处理一个mysql设置问题。 </ p>

您可能正在处理类似mysql守护程序的内容,只能侦听localhost接口,即127.0.0.1。 即使它允许来自任何主机的访问,如果它没有收听像eth0这样的提供接口,也没关系。 </ p>
</ div>

展开原文

原文

i would test your mysql database access from command line from remote machine

mysql -h vm-007.server.com -u testuser my_db -p

it will ask you for a password and type that in.

If it fails then you are probably dealing with a mysql setup problem.

likely you are dealing with something like the mysql daemon only listening to the localhost interface i.e. 127.0.0.1 . Even if it allows access from any host if it isn't listening to a give interface like eth0 it doesn't matter.

dphnn333971
dphnn333971 “local”在服务器上通过“mysql”登录,然后输入“use mysql; select * from user;” 确保用户在表中,否则您将无法通过任何主机访问本地主机。 您可能需要再次添加“用户”。 作为一个附带问题,是Web服务器(php服务器)和mysql服务器是一回事。 您可能希望将主机更改为“localhost”(如果是)。
6 年多之前 回复
duanhuo7441
duanhuo7441 仍然不适用于给予用户的所有补助金。 它必须是服务器端?
6 年多之前 回复
douqiao6015
douqiao6015 我过去也遇到过同样的问题。 需要为用户授予对数据库的访问权限。 你安装了phpmyadmin吗? 如果您安装并使其正常工作,它将为您节省很多麻烦。 您可以从内部修改用户权限。 比从命令行更容易。
6 年多之前 回复
douliangbian7323
douliangbian7323 有趣。 我按照你说的做了,得到了错误'ERROR 1045(28000):访问被拒绝用户'testuser'@'vm-007.sever.com'(使用密码:是)'。 我无法想象我的设置出了什么问题。 谢谢你的回复btw。
6 年多之前 回复



如果您尚未创建数据库,请从cmd提示符处执行此操作:</ p>

  CREATE DATABASE blobblablob; 
</ code> </ pre>

现在对该名称使用USE关键字,如下所示:</ p>

  USE blobblablob;

</ code> </ pre>

现在允许您使用您的数据库:</ p>

  GRANT ALL ON'blobblablob'to'me'  @'localhost'识别'mypassword'; 
</ code> </ pre>

不要忘记用; </ code>(分号)结束所有语句。

现在输入 exit </ code>即可退出cmd提示。
您可以在浏览器中查看PHP脚本。 他们现在应该开始为该数据库工作
since你拥有控制权限。</ p>
</ div>

展开原文

原文

If you have not created a database, do it from a cmd prompt:

CREATE DATABASE blobblablob;

Now use the USE keyword for that name like so:

USE blobblablob;

Now give yourself permission to use your database:

GRANT ALL ON 'blobblablob' TO 'me'@'localhost' IDENTIFIED BY 'mypassword';

Don't forget to end all your statements with a ; (semicolon). Now get out of the cmd prompt by typing exit. You can check in your browser your PHP scripts. They should start working for that database now since you have the controluser permissions.

Go to user account->add user account->create account with user name and password... let host name be %...click ok

click privileges on created user and grant global permission.

then change ur localhost name as ip:192.168.3.2 and username as newcreatedusername and password .... save it.

open your application from any other remote system along with ip:port ---192.168.1.2:9090/dashboard/working-files/welcome.php-------press enter

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问