So I am using my cmd on my laravel folder and I tried to do (php artisan migrate:install). 2 errors came up.
[PDOException] SQLSTATE[HY000] [2006] MySQL server has gone away
[ErrorException] PDO::__construct(): MySQL server has gone away
Can anyone please explain what I did wrong?
You have Lost SQL connection to server during query. It is temporally issue. This is because of very low default setting of max_allowed_packet.
Raising max_allowed_packet in my.cnf (under [mysqld]) to 8 or 16M usually fixes it.
[mysqld]
max_allowed_packet=16M
NOTE: This can be set on your server as it's running. You need to restart the MySQL service once you are done.
Use: set global max_allowed_packet=104857600. My value sets it to 100MB.
This is not a Laravel issue, but a general MySQL Issue. Maybe the server is not running. Are you sure you're running MySQL in the background?
Check this link: MySQL Gone Away
Do the following checks in your system:
The Database Engine is running
You have created your database
You have created an user and granted permissions to the database
You have setup the user and the database in your Laravel's .env file.
After this, try to run the migrations command again, which is:
php artisan migrate
As explained Here
Let us know if that helps :).
For me the problem seemed to be that I assigned the wrong port to my Laravel project's .env file. Later, when I matched it with the my.cnf file, it worked.
I'm using Ubuntu 16.04 + nginx + MariaDB + Laravel project.
I encountered the same problem. The solution was to delete the mysql port number from 3306 or 80, and leave it empty
In files
.env DB_PORT=3306 to DB_PORT=
and on
database.php 'port' => env('DB_PORT', '3306'), to 'port' => env('DB_PORT', ''),
In my case the problem was I changed DB_HOST to localhost but it was fixed by keeping it default ie 127.0.0.1 and the port to default 3306.
Here is the configuration for localhost in xampp:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hmb
DB_USERNAME=root
DB_PASSWORD=
Although I use localhost:8081/phpmyadmin to access my db
In addition to other answers:
Try changing localhost domain to 127.0.0.1 both in .env and config/database.php.
Also If you're using git then check git status and see if any unwanted files have been changed.
Because In my case options array for mysql connection configuration in file config/database.php was blank array somehow. I checked out git checkout config/database.php file and it starting to work fine.
If someone is looking for a solution, try to clean all cache you have, you can manually delete cache files in bootstrap/cache folder.
My solution is due to fix the DB_HOST parameter. Indeed I use PHPStorm and I set the public url in .env in order to use DB tools from the IDE and this broken Laravel.
So I changed DB_HOST to localhost and Laravel now works fine.
Related
I need your help again.
Is there a way to reset all configuration in MySQL?
Here's what happened. I previously have a project installed and this time I'm setting up a new one.
In this new project, I wanted to set it up with my a new database, new username I created and password. However, when I reached the point where I had to execute php artisan migrate, it keeps throwing me an error saying PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
If not that error, it's throwing connection refused instead.
Note: I'm using laradock.
Now, I'm at the point where I'd just rather reset the whole MySQL because I'm thinking it's conflicting with my previous configuration with my previous project.
As I searched online, I've tried the following:
1. Restarted server
2. Changed db_host from 127.0.0.1 to localhost and vice-versa
3. Added the project's directory to the dev environment setting
4. Docker-compose down and then up again
5. Even uninstalled and reinstalled docker itself
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=newdbname
DB_USERNAME=newusername
DB_PASSWORD=newpassword!
All I want is to be able to execute php artisan migrate using the new credentials I set.
If you really do not need any old data in database, you can just delete them & reset up a container:
# stop mysql service
docker-compose stop mysql
# delete old mysql database
rm -rf ~/.laradock/data/mysql
# resetup mysql container
docker-compose up -d nginx mysql
You can get the mysql database location according to docker-compose.yml & env-example:
docker-compose.yml:
volumes:
- ${DATA_PATH_HOST}/mysql:/var/lib/mysql
env-example:
DATA_PATH_HOST=~/.laradock/data
I'm setting up a new Ubuntu computer, namely mysql. I've various rails app that use mysql on the socket /tmp/mysql.sock, and as they're group projects I can't change their db config options.
"mysqladmin -u root -p variables | grep socket" tells me my socket is /var/run/mysqld/mysqld.sock. I also have a mysql directory /etc/mysql.
I've read that I'm supposed to add the socket path to the my.cnf file in the etc/mysql directory, however it is locked for editing, and somehow reverts ownership immediately if I use chown to try and change it.
Please advise me how I can change where mysql sets its default socket path.
I am also trying to get to the bottom of this, but have yet to find the definitive answer. It looks like the socket path of mysql is different between a mac and a ubuntu machine.
I initially created my app on my mac, where the socket path is:
/tmp/mysql.sock. When I tried to run rake db:create on my ubuntu machine it kept complaining that the socket does not exist. I had a look at what it is called on my ubuntu machine, which was /var/run/mysqld/mysqld.sock. When I switch it out in database.yml it seems to work, but I guess I will have to keep both options in my file and uncomment based on which environment I am working in.
Hope that helps!
This is my first time installing a framework, and I am pretty clueless.
I am on OSX 10.7 and I have the cakephp framework loaded into /Library/WebServer/Documents/cakephp and I have been able to load the test page and get rid of some of the errors and warnings. Right now I am trying to resolve this
Warning (2): PDO::__construct() [pdo.--construct]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) [CORE/Cake/Model/Datasource/Database/Mysql.php, line 160]
Cake is NOT able to connect to the database.
Database connection "SQLSTATE[HY000] [2002] No such file or directory" is missing, or could not be created.
I don't really know what to do here. I have installed MySQL. Does the MySQL PDO come installed on OSX by default? or do I need to install that? How can I check if that is installed if that seems to be the problem.
UPDATE:
The PDO Mysql driver is enabled.
Also the phpinfo() for pro_mysql looks like this:
Directive Local Value Master Value
pdo_mysql.default_socket /var/mysql/mysql.sock /var/mysql/mysql.sock
However the mysql directory doesn't appear in my filesystem. should I create it? or do I nee to change this path somewhere?
UPDATE:
I think the problem is that I haven't actually set up a database. kindof dumb of me not to set up the database.
I guess I will try to figure that out now.
UPDATE:
The thing that finally solved this was that cake was looking for the Unix socket to the database in /var/mysql/mysql.sock but mysql was using the socket in /tmp/mysql.sock
I fixed this by creating a symbolic link from the /var/mysql/mysql.sock to /tmp/mysql.sock.
It looks more like MySQL itself is not installed, but the PDO libraries are compiled with your webserver. I am not sure how to check this in OSX, but you can try checkign this link out: http://www.sequelpro.com/docs/Install_MySQL_on_Mac_OS_X
EDIT
Log into MySQL (mysql -u root -p) and create the databas:
create database cakephp
Then create a new username/password and grant them access to this database. Let's say you want to create the username cakephp and the password cakepass:
GRANT ALL ON cakephp.* TO cakephp#localhost IDENTIFIED BY 'cakepass';
FLUSH PRIVILEGES;
And now your database.php config file should look like this:
<?php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakephp',
'password' => 'cakepass',
'database' => 'cakephp',
'prefix' => ''
);
}
No, MySQL does not come with OSX, you'll have to install it.
The easiest solution is to use XAMPP instead of compiling/installing MySQL yourself. It will also come with a separate Apache and PHP, if you don't want to mess with the native OSX versions.
I'm on Ubuntu 11.04. Everything works PHP, PHPMYADMIN, manual login to MySQL etc.
I have written a C application that uses MySQL. Now, when I start this application I receive the above error. I tried to prevent that from happening by linking the original file into the /tmp/ folder (ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock), however, after a while I start getting this error again - because my link has been removed, which is frustating.
What do I need to do to make this work?
The MySQL libraries are compiled with a default of /tmp/mysql.sock. The server is started up with /var/run/mysqld/mysql.sock and your $HOME/.my.cnf does not reflect this value in the [client] section.
If this is run without a valid $HOME you may need to use mysql_options with MYSQL_READ_DEFAULT_FILE.
Try linking the file in other location than /tmp/ and use it from there
I accidentally changed the "host" value for the root user inside of the user table for mysql.
I need to change it back to localhost because I changed it to arancillary2125 (my other machines DNS name) but I cannot access mysql (from PHPMYADMIN or command prompt) due to "localhost" not having permissions any more.
I am running windows XP // apache //
I have tried the following solutions but they didn't work:
https://serverfault.com/questions/92870/1130-host-localhost-is-not-allowed-to-connect-to-this-mysql-server
Whoops.
This is on your local machine, I assume? At Start->Run, enter 'services.msc' and locate the MySQL service. Stop the service.
Edit:
Find your my.ini file (usually in C:\Windows or C:\mysql, etc). If you don't have one, create one. It's just a plain ASCII file.
Alter the file, add this in the [mysqld] section: skip-grant-tables.
On the command line, issue the command net start MySQL and wait a moment, the MySQL service should start.
Still on the command line, issue the command mysql -u root and hit "ENTER". You should be logged into MySQL as the 'root' user. Carefully change your grants and then logout. Stop the MySQL service / server. Re-edit your my.ini file and remove / comment out the skip-grant-tables line, and again start the server. Try to login as root again.
Just tested this on my Win XP Pro box.
This essentially has the effect of bypassing all the grant tables and thus doesn't bother to lookup whether you're supposed to access it from that machine or not.
MySQL reference manual : --skip-grant-tables option
So I had this problem aswell, happened all of a sudden with #1130 - Host ‘localhost’ is not allowed to connect to this MySQL server.
After searching and searching I can tell you that bdl solution is the way forward, once you can log back into the server you can change the permissions about and remove the line skip-grant-tables under your my.ini mysql config file.
I would have just upvoted bdl's post but im too new on the website to do that yet.
Recreate arancillary2125 (if even on an old desk top) and then access your DB that way.