The only book I recommend for beginners is Mick’s SQL Basics Tutorial. Many people on the Internet recommend “SQL must know must be”, in fact, this book is more suitable for database operation and maintenance, for beginners friends, can not understand. Mick’s SQL Basics is easy to read and much more fun to learn. Interest is the reason to go on learning.

The following answers how the data in this book is imported into the database.

If you look at the bottom of Chapter 1-3 of Mick’s SQL Basics tutorial, “SQ Summary: SQL Statements and their types” (page 32 of the corresponding book), it’s time to import data into the database.

First, make sure you have installed mysql and navicat, the mysql graphical client. If not, follow these steps to install:

Let’s talk about how to use the mysql graphical client Navicat to import to the database.

Connect to the mysql server

If you have created a connection in the previous tutorial and successfully connected to the database.

If you open navicat, the connection icon is gray, indicating that the client is not connected to the mysql server.

Right click on the connection name and click Open Connection

Step 1, create the database

Click “New Query” under “Query” on the menu bar to open the place for typing SQL statements.

Then enter the SQL statement to create the database, click Run, you can see the SQL statement execution results.

Right-click the connection name and select “Refresh” to see the database created

Step 2, modify the database encoding

Because Chinese content will be stored in our database, we need to modify the database code, otherwise an error will be reported during the meeting. Set the database code as shown in the following figure.

After the modification, click the “OK” button.

Create a table

The icon in front of the database shop name is gray, indicating that the database is not currently in use.

Right-click the database name and choose Open Database.

Click the query under the database (shop), right-click on “New query”. The SQL statements in the query editor opened this way are for the current database.

Enter the following SQL statement to create the Product table in the query editor and click the “Run” button to execute the SQL statement.

Right-click on “Table” and select “Refresh” to see the table created. Double-click the table name to see that the created table is the same as defined in the SQL statement.

Insert data

Click on the red box in the image below to return to the query editor where the SQL statement was written.

Write the following SQL statement to insert data into the query editor.

Do not click “Run” at this point, because running will execute all the SQL in the query editor. But we’ve already executed the SQL statement that created the table, and now we just need to execute the SQL statement that created the data.

First, select the part of the SQL statement that you want to execute with the mouse.

Then click on the red box in the image below to execute only the selected SQL statement.

You can view the SQL execution results at the bottom of the interface to see whether an error is reported during the SQL operation. If no error is reported, the SQL operation is successful.

Double-click the table name, and we can see the data that has been inserted.

Ps: If you have opened the table before, you will encounter the following problem

When the selected code appears to run, the Product table does not generate data.

Solution: Close the open table and then open it again

Let’s save the SQL statement in case we need it later.

The saved SQL statement can be seen in the red box in the following figure

We can also save the SQL statement that created the database.

As you can see, the statement that creates the database is stored in the connection name (shown in red in the figure), because this part of the statement creates the database and is not specific to any database.

The SQL statements created under the database shop are stored in its own queries (shown in blue), indicating that the statements are operations for this particular database.

Double-click the saved query name to open the query editor again and edit the SQL.

Exporting a database

Follow the following figure to export the database into a file. You can then share the file with other people, who can also use your database, or as a backup of your database, if you lose the data in your database, you can use this file to recover.

After exporting successfully, we can see the SQL script file with the suffix. SQL in the path where we saved the file. This type of file is called an SQL script file.

We use the software notepad++ to open SQL script files (notepad++ for Windows, sublime text for MAC). If you don’t have this software, go to the official website and download one. This software can open various types of files, and is a must have tool for technical learning.

When you open it, you can see the SQL script file, which is the SQL statement we just wrote, and some SQL statements were added automatically when the software was exported. So an SQL script file is a.sql file that contains SQL statements. If you pay attention, you will notice that the SQL script we exported contains the following sentence:

DROP TABLE IF EXISTS product; That is, if the table already exists in the database, the SQL statement will be executed after the table is deleted.

Because sometimes the database table, if there is no this sentence will be an error.

Import the SQL script file to the database as shown in the following figure.

Select the SQL script file you want to import, the other defaults, and click Start.

The import is successful if the following information is displayed: If the following information is not displayed, an error occurs during the import. Check the error information and handle the fault accordingly.

After the import is successful, click close. Refresh the database to see the imported data.

How to import the data from Mick’s SQL Basics Tutorial into the database?

We have shown how to create a database, where to write SQL statements, export SQL script files, import SQL script files, and see how SQL script files come from. Now let’s go back to Chapter 1-3 of Mick’s SQL Basics Tutorial, SQ Summary: SQL Statements and their types (page 32 of the corresponding book).

Let’s see how to import the SQL script file from the book (createTableProduct.sql) into the database.

To illustrate the whole process, let’s delete the table we just created.

Step 1, modify the SQL script file

Open the SQL script file with notepad++ and see what’s inside.

We see that inside are SQL statements that create tables and add data.

When you run the import SQL script again, you will hear an error like this: The table already exists.

Select * from table where product is the name of the table; select * from table where product is the name of the table; select * from table where product is the name of the table;

DROP TABLE IF EXISTS Product;

Step 2, create the database

Because we’ve already created the database. If no database is available, you need to create a database first.

Step 3, import the SQL script file

Follow the steps shown below

The result shows that the import is not successful (Unsuccessfully). Let’s see how to find out the reason according to the error message.

Incorrect string value: [Err] 1366-incorrect string value: “\xD0\xF4” for column

Put this error message into the search engine, and you’ll soon find a solution. The error is due to a coding problem.

Or report the following error:

Open the SQL script file with notepad++ and change the code of the SQL script file as shown in the following figure:

After setting the encoding in notpad++, be sure to click “save” to make the SQL script file changes take effect.

I saved the modified SQL script file in the following file

Run the import SQL file again and the execution is successful. Refresh the table to see the imported data.

conclusion

With this tutorial, you have learned:

How to connect to mysql server using Navicat

How to write SQL statements in the query editor

2) How to create a database

3) How to import SQL script files

4) How to export SQL script files

5) How to import the data in Mick’s SQL Basics Tutorial

To systematically learn SQL, look at this: