Here is my code:
$dbServername = "localhost:3306"; //I also tried localhost, localhost:8080, 127.0.0.1
$dbUsername = "root1"; //new user created in myphpadmin
$dbPassword = "mypassword"; //I used a new password for the above user
$dbName = "loginsystem"; //the database exists in myphpadmin
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
if (!$conn) {
die('error connecting to database');
}
echo 'you have connected successfully';
For the dbServername, I've tried using localhost, localhost:8080, localhost:3306 and 127.0.0.1, but only 127.0.0.1 and localhost:3306 seem to go through and gives me the error at stake. I get different errors with localhost (No such file or directory*) and localhost:8080 (MySQL has gone away).
So given the IP as dbServername seems to passthrough and go to username and password check, I assume this is right. But then I get the error Access denied for user 'root'#'localhost'.
The username root without password exists is valid myphp. The database loginsystem also exists. I tried create new usernames and passwords and connect with this and it didn't work.
Edit01: I am using iOS. The users in mysql.user are 'root' without password, and I created one called 'root1' with a password to test. These 2 do not work when I tried them in my variables. I tried create new users names and restart MySQL after creation. I also re-created my database. I have XAMPP running here: /Users/jpb/.bitnami/stackman/machines/xampp/volumes/root/htdocs/wsd/includes/dbh.inc.php.
Edit02: Added a screenshot of my user accounts overview: click here to view
*Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Users/jpb/.bitnami/stackman/machines/xampp/volumes/root/htdocs/wsd/includes/dbh.inc.php on line 8
I am running out of ideas. Hope you can help. Thank you
Edit03: I removed and un-installed XAMPP and MySQL. I installed AMPPS and now everything is fine: 'Success: A proper connection to MySQL was made.
Host information: localhost:3306 via TCP/IP'. Thank you to those who helped and let me know if you run through similar issues, maybe I can help.
Make clear your user "root" have access for login, an you use the correct host-adress.
Try to change to an other user to access.
enter image description here
Related
This is my first time using this site so apologies if I break any sort of unspoken rules as a new user, but I have been plagued with a particular problem that I can't seem to find the answer to using Google.
So I am designing a website for a friend of the family and this site uses a login/account system with phpMyAdmin databases to store all of the users and check information when logging in. I am able to login perfectly fine when I host the website on localhost using XAMPP, however when I host the server on my domain and try to press the login button using the same credentials, I receive the following error message:
Connection failed: Access denied for user 'root'#'localhost' (using password: NO)
For reference, I am using Sentora to VPS host my website. I have exported the database I am using to store the login information from my Localhost phpMyAdmin into my Sentora phpMyAdmin. In order to connect to the database, I use the following code as an included PHP file that activates whenever a database needs to be accessed:
<?php
//Database Handler
$servername = "localhost";
$dBUsername = "root";
$dBPassword = "";
$dBName = "zadmin_barber";
$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName);
if(!$conn){
die("Connection failed: ".mysqli_connect_error());
}
Whenever I try to search up the cause of this problem on Google, I am only able to find tutorials for when this error appears when logging into phpMyAdmin. I, however, have no problem logging into my phpMyAdmin. I have tried changing the settings on both privileges and users in phpMyAdmin, but no combination allowed me to login with any credentials. For more reference, here is a picture of my phpMyAdmin users:
My phpmyadmin users:
And here is a picture of the privileges of the database I am trying to access:
Database prvileges:
If you look at your picture there is no access to the database for Any users from the host "localhost".
It is not recommended to connect to DB without any password. Simply create new user with any username, assign it a password, make sure it is "localhost" in the host settings.
Then open users click edit privileges and give all the privileges to the database zadmin_barber
And one thing, don't use root to connect to database from your scripts. Creating user in MySQL is very easy.
Its been a while since i didn't use php and get error for connection to MySQL.
What I have tried: I tried username root, empty password and gives same error, but when tried ip of actual machine it gives me is not allowed to connect to this MariaDB server.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "MyGuests";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else echo "connection sucessfull";
Other errors:
In phpmyadmin localhost when i click user accounts tab it gives me #126 - index for table '.\mysql\user.MYI' is corrupt; try to repair it.
I tried username root, empty password and gives same error
So the error speaks for itself, access is denied.. Double check the privileges, is the root account allowed to connect and use that database? Make a new user account and try logging into phpMyAdmin with it, can you then access the database MyGuests?
when tried ip of actual machine it gives me is not allowed to connect to this MariaDB server
Make sure you allow a username to connect from host name 127.0.0.1 (or the IP you are connecting from, if not localhost). Check in mysql.users, you should see the host name and user. In phpmyadmin via User Accounts.
Other errors: In phpmyadmin localhost when i click user accounts tab it gives me #126 - index for table '.\mysql\user.MYI' is corrupt; try to repair it.
This might be a cause: this is where the user accounts are stored. Repairing it can be done with the query: REPAIR TABLE mysql.user
I am new to php and can't seem to solve this issue that I have.
Basically I want to build a data base and access it on my website.
I downloaded MAMP on my mac to run the site locally until I publish my site.
I made a database using phpmyadmin.
The database is a table that consists of 5 rows and 4 columns (but will increase in the future).
The following is my code to connect to database called hello:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "hello";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "connected to database";
}
?>
However I get this error as it seems that I cannot connect to the database.
Connection failed: Access denied for user 'root'#'localhost' (using password: YES)
I have tried different things like adding in a space for the password or setting it to root but they don't seem to work.
I dont understand how there is a password set on the database when I never set one.
I dont understand how there is a password set on the database when I never set one.
Because MAMP sets one by default.
Their documentation also tells you how to change it:
Open the Mac OS Terminal Application located in your /Applications/Utilities directory.
Enter the following command line: /Applications/MAMP/Library/bin/mysqladmin -u root -p password
[NewPassword]
Replace [NewPassword] with your new password.
Please bear in mind that you also have to change the phpMyAdmin configuration and probably your own php scripts to use the newly
created MySQL password. For changing the phpMyAdmin configuration edit
the following file and update the password. /Applications/MAMP/bin/phpMyAdmin/config.inc.php
… don't write applications that log in as root though. Create a new user with just as many permissions as they need.
I am trying to use mysqli to insert some data into a MySQL database (let's call the schema myDatabase), but cannot successfully connect. Here's the code snippet to connect:
...
$config = parse_ini_file('../includes/config.ini');
$username = $config['username'];
$password = $config['password'];
$dbname = $config['dbname'];
$server = $config['server'];
$conn = new mysqli($server, $username, $password, $dbname);
if (!$conn || $conn->connect_error) {
die( 'Connection Failed: ('.$conn->connect_errno.') '.$conn->connect_error);
}
...
I get the following result:
Connection Failed: (1045) Access denied for user 'myUser'#'my.laptop.ip.address' (using password: YES)
Here's some details on the set-up, in case they are relevant:
The code is on my laptop running Windows 7 and using PHP 5.3.5 that came with xammpp.
The database is hosted on a remote server with MySQL5.1.52. I created a user to which I granted all privileges on myDatabase.*. No host was specified for the user (e.g. 'myUser'#'%'), as I am still in development and don't know the ip address where the code for the live application will be hosted.
If I ssh onto the database server, I can connect to mysql using the credentials for myUser and access the tables in myDatabase. I have another schema on this same server which is accessed by a different user, and have been able to use mysqli to connect without any problems.
Just to be sure it wasn't a typo, I dropped the user, and created it again, copying and pasting the username and password from the config.ini file used in my php code (and flushed privileges, of course). I did this again, except this time the host was specified, e.g. CREATE USER 'myUser'#'my.laptop.ip.address' IDENTIFIED BY 'myPassword'. I keep getting the same error and now I'm completely stumped.
Help, please.
On your mysql machine hit:
GRANT ALL PRIVILEGES ON database.* TO 'myUser'#'%' IDENTIFIED BY 'newpassword';
FLUSH PRIVILEGES;
This will allow the user to connect from any host. Once it works, you can limit it to just a specific host and database.
Okay, this is strange, but it appears the problem had to do with the password I was using. The original one contained some special characters ($, & +). When I changed it so that it only contained numbers, letters and underscore, it worked.
Is this real, or did I accidentally do something else without realizing that turned out to be the actual solution?
Here is my code:
<?php
require_once('config.php');
$link = mysqli_connect($db_host, $db_user, $db_pass, $db_name) or die ('Your DB connection is misconfigured. Enter the correct values and try again.');
?>
I have stored my host, username, password and database name in the separate file config.php. I know that the information is correct because I can connect to my database via putty, but I keep getting the error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user
'blank'#'T9AF3.WPA.blank.Ca' (using password: YES) in
C:\xampp\htdocs\temp2\index.php on line 3 Your DB connection is
misconfigured. Enter the correct values and try again.
Note: 'blank' is there to protect my identity and is not a typing error.
Edit: I only used putty to test that my login information was correct. Putty has very little to do with my actual question.
Edit2:
<?php
$db_host = 'host';
$db_user = 'user';
$db_pass = 'pass';
$db_name = 'dbname';
?>
These are filers.
if you can login from putty, by that i think you mean localhost, and you can't from php file, which is i think trying to connect remotely, the problem most probably lies on your user not defined for your servers ip. your server, which you are trying to connect from is 'T9AF3.WPA.blank.Ca'
in mysql a username has a password and a location and mysql uses both to authenticate the user. you can have permission to connect locally but not remotely i.e. from another server. check with your system admin to make sure you have proper access defined from 'T9AF3.WPA.blank.Ca'.
Or you have not specified an IP Address for the server to listen to. It may only be listening on localhost of your server, instead of allowing remote connections. Check your mysql configuration and which IP address it is listening on.
Your mysql user must have proper rights on the database you are using