I haven't learned MySQL for a long time, and the operations of the database are nothing more than adding records, searching for records, deleting records, and modifying records.
The following commands are summarized and shared with everyone:
Connection command: mysql -h[host address] -u[user name] -p[user password]
Create database: create database [library name]
Show all databases: show databases;
Open a database: use [library name]
Currently selected library status: SELECT DATABASE();
Create a data table: CREATE TABLE [table name]([ Field name] [Field type]([Field requirements]) [Field parameters], ...);
Show data table fields: describe table name;
Current database table structure: show tables;
Change table
ALTER TABLE [table name] ADD COLUMN [field name] DATATYPE
Description: Add a column (there is no syntax to delete a column.
ALTER TABLE [table name] ADD PRIMARY KEY ([field name])
Description: Change the definition of the table and set a field as the primary key
ALTER TABLE [table name] DROP PRIMARY KEY ([field name])
Description: Delete the definition of the primary key.
Show columns from tablename;
Delete database: drop database [database name];
Delete table: drop table [table name];
Data operations.
Add: INSERT INTO [table name] VALUES('','',...data arranged in order);
Query: SELECT * FROM [table name] WHERE ([condition]);
Create index: CREATE INDEX [index file name] ON [table name] ([field name]);
Delete: DELETE FROM [table name] WHERE ([condition]);
Modify: UPDATE [ Table name] SET [Modify content such as name = 'Mary'] WHERE [Condition];
Import external data text:
1. Execute external sql script
Execute on the current database: mysql < input. sql
Execute on the specified database: mysql [table name] < input.sql
2. Data transfer command load data local infile "[file name]" into table [table name];
Back up database (under dos)
mysqldump --opt school>school.bbb