Laravel Homestead- MySQL default credentials and database - laravel

I have setup Laravel and trying to run the artisan migrate command however I am getting the error below
[PDOException] SQLSTATE[HY000] [2002] Connection refused.
I am not sure how db is setup in Homestead. So I got the below questions.
Is default database created automatically by artisan migrate or Homestead?
If it is, what is the name of it?
If its not created by default, should we create before running migration?
I tried logging in to MySQL db by connecting to Homestead VM using ssh and then running MySQL. However I get error Access denied for user.... for user name vagrant, Homestead and forge.
What is the default credentials?
I understand that creating MySQL db is out of the scope of Laravel tutorial; So it would be helpful if anyone can answer these questions and point me in right direction.

Homestead comes with a default database called homestead. Your app can either choose to hook into that database, or you will have to go and make a new database manually. You can either use a GUI (like Sequel Pro on Mac) or perform it via the command line through Vagrant.
// SSH into the box
vagrant ssh
// Connect to MySQL as the homestead user (password is: secret)
mysql -u homestead -p
// Create a new database in MySQL
CREATE DATABASE your_app_name;
// Leave MySQL
exit;
You can then migrate the database as usual, php artisan migrate.
If you need to do this with Postgres instead, it's pretty similar.
// Connect to Postgres (password is: secret)
psql -U homestead -h localhost
// Create a new database in Postgres
CREATE DATABASE your_app_name;
// Leave Postgres
\q

Related

Accessed FTP and MYSQL 8.1 for an old sql server caused site to crash [duplicate]

I am using php mysqli_connect for login to a MySQL database (all on localhost)
<?php
//DEFINE ('DB_USER', 'user2');
//DEFINE ('DB_PASSWORD', 'pass2');
DEFINE ('DB_USER', 'user1');
DEFINE ('DB_PASSWORD', 'pass1');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'dbname');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if(!$dbc){
die('error connecting to database');
}
?>
this is the mysql.user table:
MySQL Server ini File:
[mysqld]
# The default authentication plugin to be used when connecting to the server
default_authentication_plugin=caching_sha2_password
#default_authentication_plugin=mysql_native_password
with caching_sha2_password in the MySQL Server ini file, it's not possible at all to login with user1 or user2;
error: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in...
with mysql_native_password in the MySQL Server ini file, it's possible to login with user1, but with user2, same error;
how can I login using caching_sha2_password on the mySql Server?
I solve this by SQL command:
ALTER USER 'mysqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
which is referenced by https://dev.mysql.com/doc/refman/8.0/en/alter-user.html
if you are creating new user
CREATE USER 'jeffrey'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
which is referenced by https://dev.mysql.com/doc/refman/8.0/en/create-user.html
this works for me
As of PHP 7.4, this is no longer an issue. Support for caching_sha2 authentication method has been added to mysqlnd.
Currently, PHP mysqli extension do not support new caching_sha2 authentication feature.
You have to wait until they release an update.
Check related post from MySQL developers: https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
They didn't mention PDO, maybe you should try to connect with PDO.
ALTER USER 'mysqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
Remove quotes (') after ALTER USER and keep quote (') after mysql_native_password BY
It is working for me also.
If you're on Windows and it's not possible to use caching_sha2_password at all, you can do the following:
rerun the MySQL Installer
select "Reconfigure" next to MySQL Server (the top item)
click "Next" until you get to "Authentication Method"
change "Use Strong Password Encryption for Authentication (RECOMMENDED)" to "Use Legacy Authentication Method (Retain MySQL 5.X Compatibility)
click "Next"
enter your Root Account Password in Accounts and Roles, and click "Check"
click "Next"
keep clicking "Next" until you get to "Apply Configuration"
click "Execute"
The Installer will make all the configuration changes needed for you.
Like many many people, I have had the same problem. Although the user is set to use mysql_native_password, and I can connect from the command line, the only way I could get mysqli() to connect is to add
default-authentication-plugin=mysql_native_password
to the [mysqld] section of, in my setup on ubuntu 19.10, /etc/mysql/mysql.conf.d/mysqld.cnf
It's working for me (PHP 5.6 + PDO / MySQL Server 8.0 / Windows 7 64bits)
Edit the file C:\ProgramData\MySQL\MySQL Server 8.0\my.ini:
default_authentication_plugin=mysql_native_password
Reset MySQL service on Windows, and in the MySQL Shell...
ALTER USER my_user#'%' IDENTIFIED WITH mysql_native_password BY 'password';
I ran the following command
ALTER USER 'root' # 'localhost' identified with mysql_native_password BY 'root123'; in the command line and finally restart MySQL in local services.
If you're on a Mac, here's how to fix it. This is after tons of trial and error. Hope this helps others..
Debugging:
$mysql --verbose --help | grep my.cnf
$ which mysql
/usr/local/bin/mysql
Resolution:
nano /usr/local/etc/my.cnf
Add: default-authentication-plugin=mysql_native_password
-------
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default-authentication-plugin=mysql_native_password
------
Finally Run: brew services restart mysql
Now you can upgrade to PHP7.4 and MySQL will go with caching_sha2_password by default, so default MySQL installation will work with mysqli_connect No configuration required.
I tried this in Ubuntu 18.04
and is the only solution that worked for me:
ALTER USER my_user#'%' IDENTIFIED WITH mysql_native_password BY 'password';
If you have not yet already changed your MySQL default authentication plugin, you can do so by:
Log in as root to MySQL
Run the following SQL command:
a. if you are running MySQL in a different server:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';
b. if you are running MySQL in a different server:
ALTER USER 'root'#'%' IDENTIFIED WITH mysql_native_password
BY 'password';
I am using laravel 5.8 and having MAMP server got this error resolved by adding DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock in .env file like below
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8889
DB_DATABASE=dbname
DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
In my case when I was using WAMP server I fixed it using following
Note the port in mySQL's "my.ini" file. In my case it was changed to 3308 when I was switching b/w MariaDB and MySQL DB.
Use the port number when you create mysqli object.
Using the above steps I was able to run the program successfully.
phpMyAdmin GUI way
Note: This method may not work if you have the problem with root user account.
Login to phpMyAdmin as root.
Switch to "User Accounts" tab.
Select the username you get error with.
From the top buttons, switch to "Login Information" section.
In "Login Information" box, change "Authentication plugin" from "Caching sha2 authentication" to "Native MySQL authentication". Also, you must fill in other required fields, obviously, including username and password.
Save it by clicking on the "Go" button at the bottom.
Return back to terminal and enjoy. :)
In my case, i'm using PHP Symfony framework and it's a silly mistake.
The database credential was wrong in paramers.yml.
After changing the credentials accordingly the problem was gone.
In Digital Ocean Managed Mysql, we have an option to change encryption, you can change to legacy and it'll work ok.
I think it is not useful to configure the mysql server without caching_sha2_password encryption, we have to find a way to publish, send or obtain secure information through the network. As you see in the code below I dont use variable $db_name, and Im using a user in mysql server with standar configuration password.
Just create a Standar user password and config all privilages. it works, but how i said without segurity.
<?php
$db_name="db";
$mysql_username="root";
$mysql_password="****";
$server_name="localhost";
$conn=mysqli_connect($server_name,$mysql_username,$mysql_password);
if ($conn) {
echo "connetion success";
}
else{
echo mysqli_error($conn);
}
?>

phpmyadmin cannot log in to the MySQL server in laravel valet

I tried to install a phpmyadmin in laravel valet. after i run
brew install phpmyadmin I run valet link and visit the phpmyadmin in the browser by typing phpmyadmin.test
I assume that the default username and password would be 'root' and blank
but when i try to login i encounter this error
screenshot: https://prnt.sc/lva5yu
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
If you want to use MySQL 8.0 and not get the "caching_sha2_password plugin" error, then check out a couple blog posts I wrote on how to setup MySQL 8.0 in Docker with persistent data, as well as a post on how to run your MySQL 8.0 container with mysql_native_password.
In short, you can create a local "my.cnf" config file:
$ sudo nano /usr/local/opt/mysql/config/my.cnf
Add the necessary config statement to it:
[mysqld]
default-authentication-plugin=mysql_native_password
And then include that file as a volume bind in your "docker run" statement:
$ docker run --restart always --name mysql8.0 -v/usr/local/opt/mysql/8.0:/var/lib/mysql -v /usr/local/opt/mysql/config:/etc/mysql/conf.d -p 3306:3306 -d -e MYSQL_ROOT_PASSWORD=your_password mysql:8.0
You can read more detail on these steps here:
https://medium.com/#crmcmullen/how-to-run-mysql-in-a-docker-container-on-macos-with-persistent-local-data-58b89aec496a
https://medium.com/#crmcmullen/how-to-run-mysql-8-0-with-native-password-authentication-502de5bac661

Cant connect to google cloud SQL from Compute Engine Instance

I have a Laravel application running on Google Compute Engine instance. I have configured it to connect to a Cloud SQL database Instance, when I SSH to the VM and run php artisan migrate everything runs smoothly. But when I open the application in a browser I get this Error SQLSTATE[HY000] [2002] Permission denied I cant figure out what is going wrong here, I have tried cloud sql proxy but still the application cant establish a DB connection when accessed from a browser. Can anyone figure out the cause of this weird behavior.
I solved this by enabling httpd_can_network_connect_db flag in selinux by running this command.
sudo setsebool -P httpd_can_network_connect_db=1
I also faced another issue with SELinux with redis and solved it by running this command.
sudo semanage port -m -t http_port_t -p tcp 6379

FATAL: no pg_hba.conf entry for host when setting up blazer gem

My application uses the blazer gem for visualizing DB queries.
During the setup I've encountered the following error:
FATAL: no pg_hba.conf entry for host "111.22.33.44", user "blazer", database "my_db", SSL off
My application is hosted on EngineYard and uses PostgreSQL.
How can I find and modify the pg_hba.conf on EngineYard?
upd
I do have SSH access to EngineYard cloud.
Instance: General Purpose (M3) Large.
OS: EngineYard's Gentoo.
You can try the following steps. I've assumed that your DB name is my_db.
Connect to the instance via SSH (the link can be found on the EngineYard environment page)
Connect to the
database as superuser psql -U postgres -h localhost -d
my_db. If you don't have the password, check your database secrets here /data/my_db/current/config/database.yml
After connecting to DB identify location of hba file by typing SHOW
hba_file;
Quit psql by typing \q
Use previously identified path to open the hba_file file and add the missing user. E.g via vim sudo vim /db/postgresql/9.5/data/pg_hba.conf. Note the sudo command
The use should be added under # IPv4 postgres
user for 10.x with md5:
Connect to the database again
Reload the configuration via select pg_reload_conf(); command
After all steps are performed, Blazer queries should be accessible.

PDOException:SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket

whenever i run the following command php artisan migrate:install, i will get the following error in my ubuntu 12.04 terminal...
[PDOException]
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket ' /var/run/mysqld/mysqld.sock' (2).
I install laravel 5 in ubuntu 12.04. In my /var/run/mysqld folder, i don't have any mysqld.sock file. Everyone says check out your .env file but i don't have any .env.example file but yes i have app.php, database.php mail.php, cache.php files in my app/config folder.In the whole process i have conclude on thing that their is a problem with connectivity with database because whenever i want to migrate any table in database i will not migrate or not shown in database but i will create table file in my app/controller/http folder. So the problem is table is not displayed in database after i run php artisan migrate command else it will show error above mentioned. So plz help me out. Thankss.......
make sure that MySQL server is up and running, e.g. telnet 127.0.0.1 3306
replace 'localhost' with '127.0.0.1' in env('DB_HOST',

Resources