Common MySQL database command _ MySQL

Source: Internet
Author: User
MySQL database commonly used commands reproduced from: http://wenku.baidu.com/link? Url = response

Connect to the MySQL database through the command line

Format: mysql-h host address-u user name-p user password database
1. connect to MySQL on the local machine.
First, open the cmd command line, type the command mysql-uroot-p, and press enter to prompt you to enter the password. enter the password and press enter to enter MYSQL. the MySQL prompt is: mysql>
Example:
C:/> mysql-uroot-pmysql test


Mysql> show databases; displays all databases


Mysql> use mysql; switch database


Mysql> show tables; displays all tables in the database


Mysql> exit; (press enter) to exit mysql


2. connect to MySQL on the remote host. Assume that the IP address of the remote host is 192.168.1.22, the user name is root, and the password is root. Type the following command:
C:/> mysql-h192.168.1.22-uroot-proot
(Note: You do not need to add spaces for u and root. The same applies to others)
3. exit MySQL command: exit (press enter)
MySQL console commands
1. start and close the database
> Net start mysql
> Net stop mysql
Therefore, the command must be the first line and end with a semicolon:
All text commands must be first on line and end ";"


2. log on to the database based on the user name and password
> Mysql-uroot-p;
If the database does not have a password, use
> Mysql-uroot;
3. check the number of databases on the current server.

> Show databases;

4. delete a database
> Drop database databaseName;
> Commit;
5. create a database
> Create database databaseName;
6. select a database
> Use databaseName;
7. view the number of tables in the database
> Show tables;
8. create a table
> Create table tableName (
Id bigint...
Name varchar (20 )...
...
);
9. display table structure
> Describe tableName;
10. add and view data to the table
> Insert into tableName (id, name...) values ('1', 'admin ',...);
> Select * from tableName;
11. import the. SQL file (the file path is F:/file. SQL
> Source F:/file. SQL;
12. delete a table
> Drop table tableName;
13. delete all data in the table, but the table structure still exists.
> Delete from tableName;
14. update the data in the table. if there is no where, all records will be affected.
> Update tableName set name = 'admin' where id = '1 ';

15. view the server version and current date
> Select version (), current_date;
> Select version ();
> Select now ();
16. use mysql as a simple calculator
> Select pi ();
> Select pi () * 10;
17. View Users
> Select user ();
18. use load
> Load data local infile filePath into table tableName

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.