Teachnique
      CourseRoadmaps
      Login

      HomeIntroductionFeaturesVersionsVariablesInstallationAdministrationPHP SyntaxNode.js SyntaxJava SyntaxPython SyntaxConnectionWorkbench

      Create DatabaseDrop DatabaseSelect DatabaseShow DatabaseCopy DatabaseDatabase ExportDatabase ImportDatabase Info

      Create UsersDrop UsersShow UsersChange PasswordGrant PrivilegesShow PrivilegesRevoke PrivilegesLock User AccountUnlock User Account

      Create TablesShow TablesAlter TablesRename TablesClone TablesTruncate TablesTemporary TablesRepair TablesDescribe TablesAdd/Delete ColumnsShow ColumnsRename ColumnsTable LockingDrop TablesDerived Tables

      QueriesConstraintsInsert QuerySelect QueryUpdate QueryDelete QueryReplace QueryInsert IgnoreInsert on Duplicate Key UpdateInsert Into Select

      Create ViewsUpdate ViewsDrop ViewsRename Views

      IndexesCreate IndexDrop IndexShow IndexesUnique IndexClustered IndexNon-Clustered Index

      Where ClauseLimit ClauseDistinct ClauseOrder By ClauseGroup By ClauseHaving ClauseAND OperatorOR OperatorLike OperatorIN OperatorANY OperatorEXISTS OperatorNOT OperatorNOT EQUAL OperatorIS NULL OperatorIS NOT NULL OperatorBetween OperatorUNION OperatorUNION vs UNION ALLMINUS OperatorINTERSECT OperatorINTERVAL Operator

      Using JoinsInner JoinLeft JoinRight JoinCross JoinFull JoinSelf JoinDelete JoinUpdate JoinUnion vs Join

      Unique KeyPrimary KeyForeign KeyComposite KeyAlternate Key

      TriggersCreate TriggerShow TriggerDrop TriggerBefore Insert TriggerAfter Insert TriggerBefore Update TriggerAfter Update TriggerBefore Delete TriggerAfter Delete Trigger

      Data TypesVARCHARBOOLEANENUMDECIMALINTFLOATBITTINYINTBLOBSET

      Regular ExpressionsRLIKE OperatorNOT LIKE OperatorNOT REGEXP Operatorregexp_instr() Functionregexp_like() Functionregexp_replace() Functionregexp_substr() Function

      Fulltext SearchNatural Language Fulltext SearchBoolean Fulltext SearchQuery Expansion Fulltext Searchngram Fulltext Parser

      Date and Time FunctionsArithmetic OperatorsNumeric FunctionsString FunctionsAggregate Functions

      NULL ValuesTransactionsUsing SequencesHandling DuplicatesSQL InjectionSubQueryCommentsCheck ConstraintsStorage EnginesExport Table into CSV FileImport CSV File into DatabaseUUIDCommon Table ExpressionsOn Delete CascadeUpsertHorizontal PartitioningVertical PartitioningCursorStored FunctionsSignalResignalCharacter SetCollationWildcardsAliasROLLUPToday DateLiteralsStored ProcedureExplainJSONStandard DeviationFind Duplicate RecordsDelete Duplicate RecordsSelect Random RecordsShow ProcesslistChange Column TypeReset Auto-IncrementCoalesce() Function

      Useful FunctionsStatements ReferenceQuick GuideUseful ResourcesDiscussion

      Feedback

      Submit request if you have any questions.

      Course
      Database Import

      MySQL Tutorial

      This SQL tutorial is structured for beginners to guide them from the foundational concepts to advanced data manipulation and querying techniques in SQL. By the end of this tutorial, you will have developed a robust understanding of SQL, equipping you with the knowledge to efficiently manage and analyze data across various database systems. This guide sets the stage for your growth into a skilled data professional, ready to tackle complex data challenges and contribute to the field of data analysis and database management.

      Database Import

      As we learned in the previous tutorial about 'Database Export', now we'll learn how to import the exported data, or backup, into an existing MySQL database. This process is known as database import.
      In MySQL, to import an existing dump or backup file into a database, we use the mysql command-line tool.

      Importing Backup Data

      We can import the backup data into an MySQL database using the mysql command-line tool. It takes the username, database name, and the backup file with the data.

      Syntax

      Following is the syntax of mysql command-line tool
      $ mysql -u username -p new_database_name < dumpfile_path
      Where,
      • username: This is the MySQL username to use when connecting to the MySQL server.
      • new_database_name: The name of the database where you want to import the data.
      • dumpfile_path: It is the path of the backup file. The data will be imported from this file.
      • <: This symbol imports the data from the file named output_file_path.

      Example

      In this example, we will import the file named "data-dump.sql" that was generated in the previous tutorial (Database Export). The file contains a table named 'CUSTOMERS'.
      Before doing that, let us login to MySQL server as a user to create a new databases
      $ mysql -u root -p
      After logging in, it will bring you into MySQL command-line. Now, create a new database named testdb using the below query
      CREATE DATABASE testdb;
      When we execute the above query, the output is obtained as follows
      Query OK, 1 row affected (0.01 sec)
      To exit from the MySQL command-line, execute \q. Now, from the normal command line, we can import the dump file 'data-dump.sql' using the following query.
      Once we execute the below statement, we need to enter our MySQL server password.
      $ mysql -u root -p testdb < data-dump.sql
      If the above command is runs successfully, it won't show any visible output. Instead, it imports the data. If any error occur during the execution, MySQL will display them to the terminal.

      Verification

      To verify whether the import was successful, execute the following query to login into MySQL command-line
      $ mysql -u root -p
      Now, select the current database to 'testdb' using the following MySQL 'Use' query
      Use testdb;
      Execute the following query to check whether the table named CUSTOMERS in "data-dump.sql" file has been imported or not
      Show Tables;
      As we can see the output below, the CUSTOMERS table has been succesfully imported into the new database 'testdb'.
      Tables_in_testdb
      customers
      Let us also verify whether the records has been imported or not by executing the below query
      select * from customers;
      The records are also successfully imported.
      ID
      NAME
      AGE
      ADDRESS
      SALARY
      1
      Ramesh
      32
      Ahmedabad
      2000.00
      2
      Khilan
      25
      Delhi
      1500.00
      3
      Kaushik
      23
      Kota
      2000.00
      4
      Chaitali
      25
      Mumbai
      6500.00
      5
      Hardik
      27
      Bhopal
      8500.00
      6
      Komal
      22
      Hyderabad
      4500.00
      7
      Muffy
      24
      Indore
      10000.00