I do not use the database graphics operating software, with the terminal directly manipulate databases and tables.
First, the database :
- Login database system: mysql-h hostname-u user name-P, press "enter" to display "Enter Password", enter the password after the login success.
- View database: show databases;
- Select database: Use + database name;
- Creating database: Create databases + database name;
- Delete database: Drop database + DB name;
Again, the table :
Note: Select the database before creating the table: use database name;
1. See what tables are under the database show tables;
2. Create TABLE table name (property name, data type, constraint) property name and data type for the creation tables Needless to say, there are a few common constraints. The primary key represents the primary key, not NULL for non-null, auto_increment for auto-increment, and default for the property defaults.
Need to say is if the previous database is not set encoding method, to add a sentence engine=innodb default charset=utf-8 collate utf8-general-ci; If you do not have this sentence after you add a field to the table will appear in the Chinese phenomenon.
3. View table BASIC structure desc + table name; View table detail structure show create TABLE + table name
4. Modify the table:
- Modify table name: ALTER TABLE name rename new table name;
- Modify data type: ALTER TABLE name modify property name data type;
- Modify field name: ALTER TABLE name change old Property new property new data type;
- Add field: ALTER TABLE name add property name data type constraint after an existing field property name;
- Delete field: ALTER TABLE name drop property name;
- Delete tables: drop table table name
mysql--creation, use, modification, and deletion of databases and tables