my.cnf文件中没有绑定地址 - Laravel

时间:2015-09-07 11:39:22

标签: php laravel laravel-5 artisan-migrate

在运行此命令' php artisan migrate'时,我收到此错误" couldn't connect to local MYSQL server through socket"。 enter image description here

我正在查看所有stackoverflow的答案,我得到了很多建议说'将bind-address:localhost更改为127.0.0.1'。

我输入了这个命令' find / -name my.cnf'并获得了两个位置的my.cnf'文件。

  • /opt/lampp/etc/my.cnf
  • /etc/mysql/my.cnf

我很困惑..我要编辑哪个文件。哪一个是正确的路径?

而且,在我的" my.cnf" file,no' bind-address'存在。 如果我手动编写,那么在哪里写" bind-address"在my.cnf文件中?或者,我可以在该文件中的任何地方写。?

这是' my.cnf'文件

# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /opt/lampp/var/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
user = mysql
port=3306
socket      = /opt/lampp/var/mysql/mysql.sock
skip-external-locking
key_buffer = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

# Where do all the plugins live
plugin_dir = /opt/lampp/lib/mysql/plugin/

请帮助我。

2 个答案:

答案 0 :(得分:1)

我在"Project-Folder-Name/config/database.php"进行了更改。而且,它奏效了。 添加了'unix_socket' => '/opt/lampp/var/mysql/mysql.sock',

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'DatabaseName'),
            'username'  => env('DB_USERNAME', 'root'),
            'password'  => env('DB_PASSWORD', ''),
        'unix_socket'   => '/opt/lampp/var/mysql/mysql.sock', //Your sock got from above
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

答案 1 :(得分:0)

验证您的mysql服务正在运行..转到

mysql service start or mysql service restart

或者您可以查看此处提供的一些建议Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)