简体   繁体   English

MySql和PHPMyAdmin密码

[英]MySql and PHPMyAdmin password

I was given an username, password, database name and an url for accessing the phpmyadmin console for a specific application. 给我一个用户名,密码,数据库名称和一个URL,用于访问特定应用程序的phpmyadmin控制台。 Now I want to connect to the database, which ip address I also know. 现在,我想连接到数据库,我也知道该IP地址。

I tried running the following php snippet (from my local installation of xampp), which gave me an error, saying: 我尝试运行以下php代码段(来自本地安装的xampp),这给了我一个错误,说:

"Warning: mysql_connect(): Access denied for user 'xxxxxxx'@'localhost' " “警告:mysql_connect():用户'xxxxxxx'@'localhost'的访问被拒绝”

 <html> <head> </head> <body> <?php $username = "given_username"; $password = "given_password"; $db_name = "given_database_name"; $hostname = "xxxxx:3306"; //remote address //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; ?> </body> </html> 

My question is: Are the password and username for mysql and phpmyadmin the same, and, am I running this correctly? 我的问题是:mysql和phpmyadmin的密码和用户名是否相同,我是否可以正确运行?

Looking at your question, I assume the php code and the MySQL server run on different machines. 看您的问题,我假设php代码和MySQL服务器在不同的机器上运行。 In that case, you have to create a remote user in your MySQL server. 在这种情况下,您必须在MySQL服务器中创建一个远程用户。

  1. Login to your MySQL console on the MySQL server: 登录到MySQL服务器上的MySQL控制台:

    mysql -u root -p mysql -u root -p

  2. Grant access to remote user 向远程用户授予访问权限

    mysql> GRANT ALL ON given_database_name.* TO given_username@' <ip address of the php server >' IDENTIFIED BY 'given_password'; mysql> GRANT ALL ON给定的数据库名。* TO给定的用户名@' <php服务器的IP地址 >'IDENTIFIED BY'given_password';

Now you should be able to connect MySQL from remote machine. 现在您应该可以从远程计算机连接MySQL了。 If your MySQL server is behind a firewall, make sure you open incoming port of MySQL (default is 3306). 如果您的MySQL服务器在防火墙后面,请确保打开MySQL的传入端口(默认为3306)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM