How to Get MySQL 8 to Run with Laravel

How to get MySql 8 to run with laravel?

Since PHP doesn't understand caching_sha2_password, set the user back to mysql_native_password:

ALTER USER 'forge'@'localhost'
IDENTIFIED WITH mysql_native_password BY 'new_password'

Laravel 5.5 with MySQL 8.0.11: 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'

The next release of Laravel 5.5 will add support for MySQL 8.0: https://github.com/laravel/framework/pull/24038

UPDATE: Laravel 5.5.41 has been released.

How to connect to mysql with laravel?

Laravel makes it very easy to manage your database connections through app/config/database.php.

As you noted, it is looking for a database called 'database'. The reason being that this is the default name in the database configuration file.

'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database', <------ Default name for database
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),

Change this to the name of the database that you would like to connect to like this:

'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'my_awesome_data', <------ change name for database
'username' => 'root', <------ remember credentials
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),

Once you have this configured correctly you will easily be able to access your database!

Happy Coding!

laravel mysql 8 connection time out

I know it's been a while but I've found the answer. Use the following command to update your password with new authentication plugin. You can use MySQL 8 now. Have fun.

ALTER USER `username`@`localhost` IDENTIFIED WITH caching_sha2_password BY 'password';

OR

ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Difficult MySQL query (MySQL-8, Laravel)

In SQL I would do it something like

with data as 
(select
DATE_FORMAT(selections.created_at, '%Y-%m') as m,
sum(price * pumps_count) as total_price
from users
left join projects on (projects.user_id = users.id)
left join selections on (selections.project_id = projects.id)
left join pumps_price_lists on (pumps_price_lists.pump_id = selections.pump_id)
where users.id = 1
group by m
)

select *, sum(total_price) over (order by m) as cumulative_price from data

Manual set up of MySQL locally for running Laravel artisan migrate (without homestead) ERROR 2002 (HY000)

① Check if mysql is properly installed and also set up.

brew info mysql

If it's not installed then google for how to install 'mysql through homebrew'.
If it is installed do not forget to set up your mysql by doing what homebrew tells you:

We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

To connect run:
mysql -uroot

To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start

In your terminal do everything above. If you got errors, first check if your mysql server is running:

mysql.server start

Then try mysql_secure_installation and/or mysql -uroot to try and get in.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

In case of this error try: mysql -uroot -h 127.0.0.1 I don't know why but it selects the wrong host by default.

If this still doesn't work maybe you already set a password, in that case you need to add -p to the command: mysql -uroot -h 127.0.0.1 -p

If even this fails maybe it's a permission problem. Try:

sudo chown -R _mysql:mysql /usr/local/var/mysql
sudo mysql.server start

If you got in properly: That's great! Let's create our first Database.

② Creating the database you'll work with.

So if you didn't use Laravel Homestead you'll have to create your database first. Once you got into your mysql through the commands above it should say: mysql> in the terminal now.

Then just write: CREATE DATABASE my_db; where you can write any name instead of my_db. That's it!

③ Setting up your Laravel settings.

In your Laravel project folder there will be a .env file. Open that and look inside, and search for the following part:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

Even though I didn't install Laravel through homestead, it has all the 'homestead' settings... Here's what you need to change:

  1. Check if the DB_HOST is set to 127.0.0.1
  2. Set the DB_DATABASE to the one you created. In this case my_db
  3. Set a preferred DB_USERNAME or try root.
  4. Set the DB_PASSWORD to the password for MySQL you choose at the very beginning, when you set up your mysql through homebrew.

④ DONE

You're done. Try opening the terminal again, go to your Laravel project folder and php artisan migrate.



Related Topics



Leave a reply



Submit