Unable to connect to local MySQL DB using Laravel - mysql

I have a local database that I can connect to no problem using straight php
However, when I use the same settings in Laravel, I get an access denied error message
I checked stackoverflow for this type of error and most cases is solved by using 127.0.0.1. I made sure to try both 127.0.0.1 and localhost whenever asked for host/server.
Also, I made sure root had sufficient privileges
Here are my configuration settings, I tried to use different accounts, other than root, and also changing 127.0.0.1 to localhost (and the opposite)
database.php file
.env file
Hoping to learn this framework, I've heard great things. Appreciate any help

Sounds like you are trying the connection both with the script and laravel from a different Server like homestead.
Normally there are restrictions that you can't connect from remote (i.e. from a VM like homestead) to a certain server (i.e. localhost) with the root user.
Possible Solutions:
1. Create another user with the relevant permissions on mysql and connect with that one.
2. Look in the web for how to allow remote connections
3. Go the laravel way and use the homestead DB inside of the VM

First, are you sure you typed the password correctly?
Second, are you using the homestead virtual box? If yes, the default user is "homestead" and the pass is "secret" without quotes of course. Try putting that in the .env file

Related

Connecting to a remote mySql server from my local machine

My main problem right now is that I can't connect to the remote mysql server while developing on my machine. I'm trying to update a website that was previously developed by someone I do not know. I've been editing the site on my local machine but I need to access data from the mysql database that it has been using. I have the username and password that the site uses to connect to the mysql server. I can connect to it through phpmyadmin but I would like to work locally without publishing my edits to the server.
I found this here in SO and I tried running the scripts in phpmyadmin using my pc's IPaddress but I keep getting
Access denied for user 'username'#'localhost' (using password: YES)
even though I'm 100% sure I'm using the password that I used to login to phpmyadmin. I tried creating a new user but the login I'm using doesn't seem to have a Create User privilege either.
I understand that the previous developer might have a different "admin" account that has all the privileges but I have no way of knowing either.
I am a C# developer but I'm really new to MySql. Any help is greatly appreciated.
This may be a firewall issue. phpmyadmin listens on port 80 by default, but mySQL listens on port 3306. Please check the firewalls on your local PC (to make sure you can get out on 3306) and the server (to make sure you can get in on 3306).

Access denied for user 'test'#'%' to database 'db'

I'm trying to run the mysql/mysql-server docker image on a cloud container that I have, in order to connect from another container running another docker image and store data and what not in the database, as is normal.
So, reading which environment variables did what over at docker hub, I set the following variables as a test.
Connecting from the other docker image, should work if I configured everything, however, the logs says otherwise.
Access denied for user 'rolauser'#'%' to database 'test'
The line of my program that attempts to connect to the database is the following.
conn.connect("test", "confidential.hostname.here", "rolauser", "testtesttest");
I'm using libsqlpp as I'm working in C++, but the problem is unrelated to that program.
So, I have an idea of what could be going wrong. After doing some research, I have discovered that SQL servers, distinguish between users logging in from different hosts.
My thinking is that by setting a user and password via environment variables, the SQL server might be assigning this information only to rolauser # localhost. As I'm accessing the database from outside the container running the server, I don't have localhost as my hostname, thus not being able to access the database.
I don't know what else could be going wrong. I'm aware that I could try building my own image that runs a custom init file upon container startup to create the database, user and password for a wildcard hostname manually, though I'd like to know what I'm doing wrong first instead of going for a different solution.

Amazon EC2 Tomcat7 instance unable to access MySQL db on same system

I think I've seen a variety of similar posts on this topic, but am still unable to resolve my issue, so I figured I'd post with my specifics.
I have an Amazon AWS Linux EC2 instance running Tomcat7 web server. On the same machine I am also running a MySQL5 server, but I am unable to get the Tomcat app to talk to the MySQL database.
My Java app on tomcat tries to connect to MySQL by reading from a properties file:
jdbc.mysql.host.path=jdbc:mysql://localhost/
jdbc.mysql.schema=prod
jdbc.mysql.username=root
jdbc.mysql.password=<password>
I am accessing the app from another system via web browser, but when the app tries to connect to the database I get the following error in catalina.out:
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
I'm pretty sure the issue has to do with permissions and communication between Tomcat and MySQL, because I've written a simple java program utilizing the same code to read the same properties file, and the connection is made successfully.
Here are some things I have attempted to remedy the issue:
change the owner of the properties file (currently owned by 'Tomcat')
ensured that user 'root' has been granted all privileges in MySQL
ensured that port 3306 (MySQL default port) is accessible by my test server
updated iptables made various modifications to /etc/my.cnf file
(tried to bind ip, but that didn't work)
I have a hunch that the issue may be related to the fact that I am trying to access the MySQL database using user 'root'. Even though I'm accessing it via localhost, the system may not support this because MySQL treats this as access from a separate host and (maybe?) root access from other hosts isn't allowed?
Any suggestions on things to try would be greatly appreciated...
I believe the issue was a combination of things.
Here are some items to consider that ultimately fixed it for me:
- making sure you were accessing the correct app via browser (I was using ROOT app, but trying to connect to another one)
- making sure a user exists in MySQL using 'Create User ....'
- making sure all privileges are granted on the database in question, for some reason granting all privileges on . wasn't working for me

Mysql external acces not working

I have a setup of two separate Servers.
On one, there is the Website with its DB and on the other Server there is a DB the website needs to access.
so... both servers are running newest versions of Mysql and pma.
By default if i create a new Database with a user, there is a user with localhost access and one with "%" access being created.
As far as i knew the % means that it can be accessed from anywhere... so why isnt it working?
Pic of pma users: PIC
Pic of error message on the Website:PIC
Set bind-address to 0.0.0.0 in my.cnf and don't forget to restrict access with iptables ;)

My apps can't connect to mysql, can you suggest things to test?

I'm on a mac server. From my home directory, I can get to mysql on the command line. But apps I install (I've tried phpMyAdmin and then Wordpress) can't connect to mysql#localhost.
Suggestions on troubleshooting the problem?
Also, how can I tell what port mysql is running on?
Try specifying 127.0.0.1:3306 as the host and see if that works...
Edit from comments:
Use netstat -a to check which
port MySQL is listening on.
Check to make sure you have the mysql extension installed.
More information: http://us2.php.net/mysql
Make sure you have explicitly listed localhost when you granted permissions to the user. For example, if you have a database named blog which is accessed by a user named wordpress, you need to create the user with this:
grant all on blog.* to 'wordpress'#'localhost' identified by 'blahblah';
I believe that the mysql command-line utility uses Unix file sockets to connect, which bypasses any hostname or DNS restrictions.