I am trying to deploy my website to Heroku by following this tutorial: https://scotch.io/#phalconVee/deploying-a-php-and-mysql-web-app-with-heroku
Problem comes at step 11 when I need to import the database file I exported from phpmyadmin into clearDB.
It is mentioned to use this code:
mysql -u bafee8afa994 -h us-cdbr-east-05.cleardb.com -p heroku_f677d7 4dc6f < trendymarkt.sql
I had replaced the username, hostname, password and sql file with my own. However, every time I press enter after this line, it just keeps showing "-> ", and when I cancel it (ctrl+C), it says I have syntax error.
I don't actually have mysql locally installed since I am using MAMP, but I am trying to activate this code using the MAMP mySQL CLI as indicated here: http://blog-en.mamp.info/2009/08/using-mysql-command-line-with-mamp.html so this should not be the problem (?).
Also, in my php file that connects the database, am I suppose to replace the host, username, password and database with the heroku clearDB config? I did it as such:
<?php
//setting up database
$servername = "us-cdbr-east-05.cleardb.com"; //was 'localhost:8889'
$dBUsername = "bafee8afa994"; //was 'root'
$dBPassword = "4dc6fc"; //was 'root' or ""
$dbName = "heroku_01fdeda2cc1aa"; //was 'trendymarkt'
$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dbName);
if(!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
Is it okay to replace the database name? Unsure how it will recognize the database in this case...
I currently have my website deployed onto Heroku, but I am having trouble deploying the MySQL database.
Thank you.
Edit: I managed to run the mysql command, but after entering password, I get this error:
ERROR 1045 (28000): Access denied for user 'bafee8afa994'#'ip-10-0-120-40.ec2.internal' (using password: YES)
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.
I am new to web development. I recently installed LAMP stack and was trying to connect my PHP code to MySQL which established a connection and created a database (All the code was written in a directory in opt/lampp/htdocs).
<?php
$servername = "localhost:3306"; // specifying the port number seems necessary
$username = "akshay";
$password = "xxxx";
$dbname = "sys";
try {
//valid database needs to be mentioned
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully<br>";
$sql = "CREATE DATABASE myDBPDO";
// use exec() because no results are returned
$conn->exec($sql);
echo "Database created successfully<br>";
} catch(PDOException $e) {
echo "Connection Error: " . "<br>" . $e->getMessage();
}
$conn = null;
?>
And it worked fine. But when I proceeded further to create a table in my database, the server gave an error:
Connection failed: SQLSTATE[HY000] [1049] Unknown database 'myDBPRO'
I later found out that MySQL was running independently and not in the lamp stack. (i.e. it always showed "ok" whenever I ran sudo /opt/lampp/lampp start whereas Apache and ProFTPD showed "already running". I was not able to open myphpadmin either).
To connect MySQL to the LAMP, I stopped MySQL:
sudo service mysql stop
And then restarted my lamp stack: sudo /opt/lampp/lampp start (This time MySQL was connected as it showed already connected when I ran the command again and I was able to open pyphpadmin too.) So, I tried to run my code again but this time, it would not even connect. It gave the following error:
Connection Error:
SQLSTATE[HY000] [1045] Access denied for user 'akshay'#'localhost' (using password: YES)
I have the following doubts:
How was my code initially working if MYSQL was not connected to LAMP stack?
Why was the created database not present in PHPMyAdmin?
How to make MySQL work with LAMP?
(Forgive me if something is too obvious, I am quite new to this.)
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
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?