Answers for "how to upload sql file in mysql"

SQL
1

how to import .sql file in mysql database using php

<?php
$conn =new mysqli('localhost', 'root', '' , 'blog_samples');

$query = '';
$sqlScript = file('database-script.sql');
foreach ($sqlScript as $line)	{
	
	$startWith = substr(trim($line), 0 ,2);
	$endWith = substr(trim($line), -1 ,1);
	
	if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') {
		continue;
	}
		
	$query = $query . $line;
	if ($endWith == ';') {
		mysqli_query($conn,$query) or die('<div class="error-response sql-import-response">Problem in executing the SQL query <b>' . $query. '</b></div>');
		$query= '';		
	}
}
echo '<div class="success-response sql-import-response">SQL file imported successfully</div>';
?>
Posted by: Guest on November-14-2020
1

import database mysql command line

mysql -u username -p new_database < data-dump.sql
Posted by: Guest on September-13-2020
3

mysql load sql from file

mysql> use db_name;
 mysql> source file_name.sql;
Posted by: Guest on April-29-2020

Code answers related to "how to upload sql file in mysql"

Code answers related to "SQL"

Browse Popular Code Answers by Language