Export and Import Mysql  Database using  shell script in php

Export and Import Mysql Database using shell script in php

Export and Import Mysql  Database using  shell script in php  


<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('max_execution_time', '-1');
error_reporting(E_ALL);

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$db = 'alldatabackup';
$dir = 'dump.sql';

$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "CREATE DATABASE alldatabackup";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}



$mySQLDir='/Applications/MAMP/Library/bin/mysqldump';
$cmd = $mySQLDir .' -h '.$dbhost.' --user='.$dbuser.' --password='.$dbpass.' alldata > dump.sql';
exec($cmd);
echo "Import Done";


$mySQLDirec='/Applications/MAMP/Library/bin/mysql';
$cmd = $mySQLDirec.' -h '.$dbhost.' --user='.$dbuser.' --password='.$dbpass.' alldatabackup < "'.$dir.'"';
exec($cmd);
echo "Export Done";
Access MAMP's MySQL from Terminal and Import SQL database

Access MAMP's MySQL from Terminal and Import SQL database

connect like this from command line import database: 

 /Applications/MAMP/Library/bin/mysql -uUsername -pPassword 
 After provide source 

use <database>;

 source /Users/200khkjh031/Downloads/a_1712210588.sql

Obviously replace Username and Password. , there is no space between -u and the Username or -p and the Password.
Drupal Speed Optimization

Drupal Speed Optimization

 Drupal Speed Optimization


Caching

Page Cache

BigPipe

Redis

Media Optimization

Image Optimization

Responsive Images

Lazy Loaded Images


Modules & Codebase

Stay up to date

Uninstall unused modules

404 Error Pages


Content Delivery Network (CDN)


External Resources (JavaScript, CSS, etc.),


Database Optimization

Database Logging

Table Maintenance


Pageviews from the past week