简体   繁体   中英

MySql and PHPMyAdmin password

I was given an username, password, database name and an url for accessing the phpmyadmin console for a specific application. Now I want to connect to the database, which ip address I also know.

I tried running the following php snippet (from my local installation of xampp), which gave me an error, saying:

"Warning: mysql_connect(): Access denied for user '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?

Looking at your question, I assume the php code and the MySQL server run on different machines. In that case, you have to create a remote user in your MySQL server.

  1. Login to your MySQL console on the MySQL server:

    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';

Now you should be able to connect MySQL from remote machine. If your MySQL server is behind a firewall, make sure you open incoming port of MySQL (default is 3306).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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