The use of MySQL under Linux
The use of MySQL under Linux
1. Install the mysql command: sudo apt-get install-y mysql-server
2. Start the mysql command: sudo service mysql start (root permission is required to use it, without any prompt after startup)
3. Enter the mysql command after startup: mysql-u username-p password
4. Create a library: create database database_name
5. Display the list of libraries: *. Show databases
6. Select a library for operation: use database_name
7. Create a table: create table table name (column name 1 data type, column name 2 data type, …... )
Create table teacher (id int auto_increment not null primary key
Name char
Address varchar (50) default "Shenzhen"
Year date
);
Id is set as the primary key and automatically set, that is, you don't have to write to the id field when you add it.
8. Insert by row: insert into table name values (value 1, value 2,... )
Insert by column: insert into table name (column 1, column 2,... ) values (value 1, value 2,... )
9. Display the information in the table: select * from table name
10. Display the table in the library: use mysql; (open the library you want to operate)
Show tables; (display the tables in the library)
Constraint: not null (the data type is followed by not null to force the column not to accept null values).
12. Modify the data in the table: update table name set column name = new value where column name = a value
13. Delete:
① deletes rows from the table: delete
② deletes the row where the A value is located: delete from table name where column name = A value
③ deletes all lines: delete from table_name; or (delete * from table_name)
Note: open the library (use mysql;) when manipulating the library and the tables in the library.