banner
xingli

xingli

猫娘爱好者

Database Backup Import Tutorial

Basic CRUD#

Importing the Database#

Code:

Login

mysql -u root -p 123456

Create Database

CREATE DATABASE book7 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Delete Database

DROP DATABASE book7;

Import Database

mysql -u [username] -p [database] < E:\books7.sql
mysql -u root -p book7 < E:\books7.sql

Modifying for Compatibility with Older Versions of MySQL#

This error usually occurs when you are trying to transfer a database that uses the new utf8mb4_0900_ai_ci collation from MySQL 8.0 to an older version of MySQL or MariaDB server.

To resolve this issue, you need to change the collation to one supported by the older version. Follow these steps:

  1. Open the E:\books7.sql file and search for utf8mb4_0900_ai_ci.
  2. Replace all occurrences of this collation with utf8mb4_general_ci, which is supported by older versions of MySQL and MariaDB.
  3. Save the modified E:\books7.sql file.
  4. Import the file into the MySQL database again using the following command:

image-20230310133441561

Checking the Import#

image-20230310133522373

Structure of the book Table#

image-20230310133615220

To delete a column from a table, use the ALTER TABLE command and specify the name of the column to be deleted. Here's an example:

ALTER TABLE table_name DROP COLUMN column_name;

In the above command, replace table_name with the name of your table and column_name with the name of the column you want to delete.

ALTER TABLE book DROP COLUMN borrower_id;
ALTER TABLE book DROP COLUMN borrow_time;

image-20230310133853951

Inserting Book Information#

INSERT INTO book(id, name, price, upload_time) VALUES(1, 'F*cking Databases', 999, NOW());

image-20230310134302057

Inserting Multiple Books#

INSERT INTO book(name, price, upload_time)
VALUES
('F*cking Databases', 998, NOW()),
('F*cking Database Homework', 997, NOW()),
('Database Requirements', 996, NOW());

image-20230310134555599

Exporting the Database#

mysqldump -u username -p dbname > backup.sql
mysqldump -u root -p book7 > E:\book8.sql

image-20230310134756756

image-20230310134802563

Exported Content

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.