MySQL Command Daquan classic edition

Source: Internet
Author: User
Tags mysql commands

The following articles mainly introduce MySQL commands, including common MySQL database commands, modifying the actual root password in the MySQL database, and introducing the practical application of grant, the following describes the specific content of the article. I hope you will gain some benefits.

MySQL Command Daquan 1. MySQL Common commands

Create database name; create a database

Use databasename; select database

Drop database name directly deletes the database, no reminder

Show tables; displays tables

Describe tablename; Detailed description of the table

Add distinct to the select statement to remove duplicate fields.

Before MySQLadmin drop databasename deletes a database, a message is displayed.

Display current MySQL version and current date

 
 
  1. select version(),current_date;  

MySQL Command Daquan 2. Modify the root password in MySQL:

 
 
  1. shell>MySQL -u root -p   
  2. MySQL> update user set passwordpassword=password(”xueok654123″) where user=’root’;   

MySQL> flush privileges // refresh the database

MySQL> use dbname; open the database:

MySQL> show databases; displays all databases

MySQL> show tables; display all tables in MySQL: use MySQL first; then

MySQL> describe user; displays the column information of the user table in the MySQL database );

3. grant

Create a full Super User that can connect to the server from anywhere, but you must use a password something to do this

MySQL> grant all privileges on *. * to user @ localhost identified by 'something'

Add new users

Format: grant select on database. * to username @ login host identified by "password"

 
 
  1. GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY ’something’ WITH GRANT OPTION;   
  2. GRANT ALL PRIVILEGES ON *.* TO monty@”%” IDENTIFIED BY ’something’ WITH GRANT OPTION;   

Delete authorization:

 
 
  1. MySQL> revoke all privileges on *.* from root@”%”;   
  2. MySQL> delete from user where user=”root” and host=”%”;   
  3. MySQL> flush privileges;   

Create a User custom to log on to it363.com on a specific client and access the specific database fangchandb.

 
 
  1. MySQL >grant select, insert, update, delete, create,drop on fangchandb.* to custom@ it363.com identified by ‘ passwd’  

Rename a table:

 
 
  1. MySQL > alter table t1 rename t2;  

MySQL Command Daquan 4. MySQLdump

Back up database

 
 
  1. shell> MySQLdump -h host -u root -p dbname >dbname_backup.sql  

Restore database

 
 
  1. shell> MySQLadmin -h myhost -u root -p create dbname   
  2. shell> MySQLdump -h host -u root -p dbname < dbname_backup.sql   

If you only want to unload the table creation command, the command is as follows:

 
 
  1. shell> MySQLadmin -u root -p -d databasename > a.sql  

If you only want to unload the SQL command for inserting data without the table creation command, the command is as follows:

 
 
  1. shell> MySQLadmin -u root -p -t databasename > a.sql  

What should I do if I only want data and do not want any SQL commands?

 
 
  1. MySQLdump -T./ phptest driver  

Only when the-T parameter is specified can the plain text file be detached, indicating the directory where the data is detached and./indicates the current directory, that is, the same directory as MySQLdump. If no driver table is specified, the data of the entire database is detached. Each table generates two files, one of which is a. SQL file, including table creation and execution. The other is a. txt file that only contains data and does not contain SQL commands.

5. You can store the query in a file and tell MySQL to read the query from the file instead of waiting for keyboard input. You can use the shell to type the redirection utility to do this. For example, if the file my_file. SQL contains a query

Query:

For example, if you want to write a table prefix in SQL .txt:

 
 
  1. MySQL > MySQL -h myhost -u root -p database < sql.txt  

The above content is an introduction to the MySQL command list, and I hope you will get some benefits.

Related Article

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.