1. Connect to MySQL
MySQL connected to this machine
Type the command mysql-u root-p enter to prompt you for the password.
Ps: You can have a space before the user name, but there must be no space before the password
The prompt for MySQL is: mysql>
Connect to MySQL on the remote host
Format: mysql-h host name-u user name-P user Password
Assume that the IP of the remote host is: 192.168.8.113, the user name is SD password: 123456
You can type the following command:
Mysql> mysql-h192.168.8.113-u sd-p 123456 (you and SD can have no spaces, others are the same)
2. Exit the MySQL command
Mysql>exit (carriage return)
3. Displaying the database
Mysql>show databases;
4. Select a database
Mysql>use database name;
5. Displaying data tables in the database
Mysql>show tables;
6. Display the structure of the data table
Mysql>describe Data table name
7. Database creation
Mysql>create database name
8. Create a data sheet
Mysql>create Table datasheet Name
1 CREATE TABLE table name (field settings list);2 3Mysql>CREATE table name (4 5IdintAuto_increment notNULLprimary KEY,6 7UnameChar(8),8 9GenderChar(2),Ten One-birthday date); A -Query OK,0Rows Affected (0.03sec) - the - -Mysql>show tables; - ++------------------+ - +| Tables_in_userdb | A at+------------------+ - -| name | - -+------------------+ - inRowinch Set(0.00sec) - to + -Mysql>describe name; the *+----------+---------+------+-----+---------+----------------+ $ Panax Notoginseng| Field | Type | Null | Key | Default | Extra | - the+----------+---------+------+-----+---------+----------------+ + A| ID |int( One) | NO | PRI | NULL | auto_increment | the +| uname |Char(8) | YES | | NULL | | - $| Gender |Char(2) | YES | | NULL | | $ -| Birthday | Date | YES | | NULL | | - the+----------+---------+------+-----+---------+----------------+ - WuyiRowsinch Set(0.00sec) the - Wu - Note: auto_increment self-increment About $Primary KEY Primary Key
9. Deleting a database
Mysql>drop database name
Delete a table
DROP table Name
Deleting records
Delete from name where uname = ' Zhang San
10. Adding records
INSERT into name (Uname,gender)
Update Name Set birthday = ' 1996-05-16 ' where uname = ' Zhang San '
11. Display the records in the table
Mysql>select * from data table name
12. Inserting records into the table
Mysql>insert into data table name values (pair)
13. Update the records in the table
Mysql>update data table name set field name 1= ' A ', field name = ' B ',..., where ...
14. Change the root password on the command line
Mysql>update Mysql.user Set Password=password (' New password ') where user= ' root ';
Mysql>flush privileges;
15. Backing Up the database
Mysql>mysqldump-u root-p--opt database name > backup name; Go to library Directory
16. Recovering a Database
Mysql>mysql-u ROOT-P Database name < backup name; Database must exist at restore time, can be an empty database
Reference connection: http://www.cnblogs.com/xdpxyxy/archive/2012/11/16/2773662.html
Basic MySQL operation under Linux