bind-address not present in my.cnf file - Laravel

ε祈祈猫儿з 提交于 2019-11-30 09:40:21

问题


While running this command 'php artisan migrate', i got this error "couldn't connect to local MYSQL server through socket".

I was going through all stackoverflow answers, i got many suggestions saying 'change bind-address:localhost to 127.0.0.1'.

I entered this command 'find / -name my.cnf' and got two locations of 'my.cnf' file.

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

I've confusion.. Which file i've to edit. Which one is correct path ?

And, in my "my.cnf" file, no 'bind-address' is present. If i write manually, so where to write "bind-address" in my.cnf file ? Or, anywhere i can write in that file.?

Here is 'my.cnf' file

# 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/

Please Help Me.


回答1:


I made changes in "Project-Folder-Name/config/database.php". And, it worked. Added '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,
        ],



回答2:


verify your mysql service is running..try to

mysql service start or mysql service restart

Or you can checkout some of the suggestion given here Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)



来源:https://stackoverflow.com/questions/32437796/bind-address-not-present-in-my-cnf-file-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!