Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
758 views
in Technique[技术] by (71.8m points)

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

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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,
        ],

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...