Mysql command not run with exec function in php-ThrowExceptions

Exception or error:

How can I run mysql command with exec() function in php. Below code run on live aws server but can not run on my local ubuntu system. lampp server is installed on my local ubuntu system where mysql database connectivity is done and my php application is running fine but command is not running.
Error is : Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

My existing code is-

 exec(mysql -h "myhost" -u "myusername" -p"databasepassword" "databasename" < "sql_file_path/demo.sql")
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *