The composition of 1.mysql database and its related concepts first understand that MySQL is a relational database, and the biggest difference in non-relational databases is that the concept of a table is different. + The entire MySQL environment can be understood as one of the largest databases: A + is created with MySQL
DatabaseB is a, the warehouse of the data, equivalent to the folder in the System +
Data SheetC: Is the location of the data, equivalent to the file in the system, a database B contains a number of data table C (note here the database B and a is not the same) +
RecordD: A row in a data table is called a record, so when we create a data table, we must create an ID column that identifies "this is the number of records" and the value of the ID column cannot be the same and must be unique, equivalent to the identity card number. There can be more than one record in a table C d+
FieldE: Each column in a table, called "Field", in the database of each field, there are provisions, such as: The field of data type, empty and non-empty judgment, automatic growth and so on. A record D can have more than one field E. +
DataF: The intersection of rows and columns is the real "data" F. 2. Basic operation of the database (Ubuntu Environment) Common command instances. 2.1 Login MySQL:
mysql-u root-p-U: Login with user name,-P: Enter password
2.2 View the database: Enter the above command will be required to enter the password, the successful login will display the interface, see System A comes with data b
show databases;Note that the semicolon cannot be less, as shown in the system's own database.
2.3 Create a database:
CREATE DATABASE MyTestThis creates a database B, the library named MyTest.
2.4 In the above 4 databases, how to choose the database we want?
Use mytest, this selects our database mytest.
2.5 If you want to delete a database:
drop Database MyTestThis will delete the database and will not be alerted. 2.6 View the current status:
status;
2.7 shows the table C in the current database in the following two ways. A:
show tables;B:
show tables from mytest;. Where mytest is the database we created.
2.8 Data Sheet creation and deletion
CREATE TABLE mytable (id int, name int);
drop table mytable;
2.9 How to build a good data table, that is, how to insert data into a data table?
INSERT INTO MyTable (ID, name) values (1,10);2.10 Querying the data in the table,
Select Id,name from mytable where id=1 order;Or
SELECT * FROM MyTable
2.11 Updates to the data in the table,
Update mytable set name=20 where id=1;
2.12 Deletion of tables:
Delete from mytable;Or
drop table mytable;2.13 Modification of the table structure
- (1) Add a field format:
ALTER TABLE table_name add column (field name fields type); --this method with parentheses
- (2) Specify where the field is inserted:
ALTER TABLE table_name ADD column Name field type after a field;
- (3) Modify field name/type
ALTER TABLE table_name change old field name new field name type of new field;
- (4) Change the name of the table
ALTER TABLE table_name Rename to new_table_name;
- (5) Clear all data in the table at once
TRUNCATE TABLE table_name; This method also causes the number picker (ID) in the table to start at 1
- (6) Delete a field:
ALTER TABLE table_name drop field name;
2.14 Change Password Format:
mysqladmin-u username-p Old password password new password;2.15 show the structure of the table:
describe Mytables;
2.16 displaying the current database and user
Show Database (); Show user ();
3 Note: 3.1 If you make a command, you will find that you forget to add a semicolon, you do not have to re-play the command, just hit a semicolon to enter it. 3.2 You can use the cursor up and down keys to bring up previous commands.
MySQL Database usage and understanding (based on Ubuntu 14.0.4 LTS 64-bit)