Can't connect to mysql server


I’m a newbie to databases. What I’ve done is:

  • setup PhpMyAdmin Droplet
  • logged onto PhpMyAdmin using ‘admin’ user and a certain password ‘password’, and I created a database called ‘test’
  • connected using WinSCP & uploaded php file
  • run the php file as follows:

<?php $con = mysqli_connect(‘localhost’, ‘admin’, ‘password’, ‘test’) or die("Connection failed: " . mysqli_connect_errno()); ?>

Somehow, now matter what I try, it keeps giving me a connection error. Am I doing something wrong?


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

MySQL users are identified by a username and host. Additionally you should only be using your MySQL admin account to administer the MySQL server itself but not to access various databases and not to read and write information that are connected to by apps. This is for security.

Since you have created a database already called test you will want to create a new user that will access that database and read/write data to it.

To do that login to mysql as your admin account and create a user with access:

CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'replace-with-desired-password';
GRANT ALL PRIVILEGES ON test.* TO 'testuser'@'localhost';

Here you are creating a new user called testuser which can connect from localhost with the password you specified.

Then you are granting that user privileges to access, read, write, etc to the database test.*. When you write test.* that means you are giving this user access to the database test, and the * means all tables for that database.

You can also find more in depth information about users and permissions here: