php cannot connect to mysql but mysql command line operation is normal
- 2020-06-15 10:23:19
- OfStack
Failure status: The php website failed to connect to mysql, but you can log in and operate normally from the command line through the mysql command.
Solutions:
1. Log on to mysql from the command line and execute the following command:
After execution, you get an echo similar to the following:
2, editing php. ini, find mysql default_socket configuration items, 1 kind is by default empty value (using the edit Settings when Mysql sock path), add the values for the above the echo of the "/ home/mysql/data/mysql sock" :
3. Restart php.
Solutions:
1. Log on to mysql from the command line and execute the following command:
show variables like 'socket';
After execution, you get an echo similar to the following:
"Variable_name" "Value"
"socket" "/home/mysql/data/mysql.sock"
2, editing php. ini, find mysql default_socket configuration items, 1 kind is by default empty value (using the edit Settings when Mysql sock path), add the values for the above the echo of the "/ home/mysql/data/mysql sock" :
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /home/mysql/data/mysql.sock
3. Restart php.