MySQL Command Summary

Source: Internet
Author: User
Tags mysql host

1. Connect to MySQL.
Format: mysql-H host address-u user name-P User Password
1. Connect to MySQL on the local machine.
First
Open the DOS window, go to the MySQL/bin directory, type the mysql-u root-p command, and press enter to prompt you to enter the password. Note that there is a space or no space before the user name.
Space, but no space is required before the password; otherwise, you must enter the password again.
If you have just installed MySQL, the Super User Root does not have a password, so press enter to enter MySQL
MySQL prompt: mysql>
2. Connect to MySQL on the remote host. Assume that the IP address of the remote host is 110.110.110.110,
The username is root and the password is abcd123. Enter the following command:
Mysql-h110.110.110.110-u root-P 123;
(Note: you do not need to add spaces between U and root. The same applies to others)
3. Exit MySQL command: exit (Press ENTER)
2. Change the password.
Grid
Type: mysqladmin-u username-P old Password New Password
1. Add a password ab12 to the root user. First, enter the directory under DOS
MySQL/bin, and then type the following command
Mysqladmin-u root-Password ab12
Note: The root does not exist at the beginning.
Password, so the old-P password can be omitted.
2. Change the root password to djg345.
Mysqladmin-u root-P ab12 password djg345
III,
Add new users.
(Note: Unlike the above, the following commands in the MySQL environment are followed by a semicolon as the command Terminator)
Grid
Type: grant select on database. * To username @ login host identified by "password"
1. Add a user named test1.
The code is ABC, so that he can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MySQL, and then type the following command:
Grant select, insert, update, delete on *. * to [email = test1 @ "%] test1 @" % [/Email] "identified by" ABC ";
However
The added users are very dangerous. If someone knows the password of test1, then he can log on to your MySQL database on any computer on the Internet and
For the solution, see 2.
2. Add a user Test2 whose password is ABC so that he can only log on to localhost and check the database mydb.
Query, insert, modify, and delete operations (localhost refers to the local host, that is, the host where the MySQL database is located ),
In this way, the user knows the password of Test2 and does not have one.
You can only access the database through the web pages on the MySQL host.
Grant select, insert, update, delete on mydb. * to [email = Test2 @ localhost] Test2 @ localhost [/Email] identified by "ABC ";
For example
If you do not want Test2 to have a password, you can run another command to remove the password.
Grant select, insert, update, delete on mydb. * to [email = Test2 @ localhost] Test2 @ localhost [/Email] identified by "";
Lower
I am a MySQL database-related operation. Note: you must first log on to MySQL. The following operations are performed at the MySQL prompt and each command ends with a semicolon.
I,
Operation Skills
1. If you forget the extra points after you press Enter when making the command, you don't have to repeat the command. You just need to press a semicolon to press Enter.
That is to say, you can divide a complete command
The number of rows to be typed, and then use the semicolon as the end sign to OK.
2. You can use the cursor to bring up or down the previous commands.
Ii. Display commands
1. display
Database List:
Mysql> show databases;
Note: the MySQL database contains MySQL system information. You can change the password and use the new password.
Users are actually using this database for operations.
2. display data tables in the database:
Mysql> Use Database Name;
Mysql> show tables;
3,
Display the data table structure:

2nd floor

Mysql> describe table name;
4. Create a database:
Mysql> Create Database database name;
5,
Create a data table:
Mysql> Use Database Name;
Mysql> Create Table Name (Field
Name: varchar (20); field name: Char (1 ));
6. delete a database:
Mysql> drop database database name;
7,
Delete A data table:
Mysql> drop table name;
8. Clear records in the table:
Mysql> Delete from table
Name;
9. display the records in the table:
Mysql> select * from table name;
10. insert records into the table:
Mysql> insert into table
Name values ("hyq", "M ");
11. Update table data:
Mysql-> Update table name: Set field name
1 = 'A', field name 2 = 'B' where field name 3 = 'C ';
12. load data into a data table in text mode:
Mysql> load data local infile "D:/mysql.txt" into table
Name;
13. Import the. SQL FILE command:
Mysql> Use Database Name;
Mysql> source D:/MySQL. SQL;
14,
Modify the root password on the command line:
Mysql> Update mysql. User SET Password = PASSWORD ('new Password
Code') where user = 'root ';
Mysql> flush privileges;
15. display the Database Name of use:
Mysql> select database ();
16,
Display the current user:
Mysql> Select User ();
3. An instance for creating a database, creating a table, and inserting data
Drop database if exists school ;//
If school exists, delete it.
Create Database school; // create a database School
Use school; // open
Library School
Create Table teacher // create table teacher
(
Id int (3) auto_increment not null primary key,
Name char (10) Not null,
Address varchar (50) default 'shen
Comment ',
Year date
); // Table creation ends
// Insert fields as follows
Insert into teacher values (", 'allen ','
Dalian Zhongyi ', '2017-10-10 ′);
Insert into teacher values (", 'jack', 'dalian 2
Medium ', '2017-12-23 ′);
If you type the preceding command at the MySQL prompt, debugging is not convenient.
(1) You can write the above command as is
In the text file, assume it is school. SQL, then copy it to C: //, and enter the directory [url = file: // MySQL // bin] In DoS Status
// MySQL // bin [/url], and then type the following command:
Mysql-uroot-P password <C: // school. SQL
For example
If it succeeds, no display is displayed for a blank row. If an error occurs, a prompt is displayed. (The preceding command has been debugged. You only need to remove the // annotation to use it ).
(2) or use
Use mysql> source C: // school. SQL; you can also import the school. SQL file to the database.
4. convert text data to data
Database
1. Text data should conform to the format: field data is separated by the tab key, and null values are separated by [url = file: /// N] // n [/url] instead. example:
3 rose
Lian 2, 1976-10-10
4 Mike Dalian No. 1 1975-12-23
Assume that you save these two sets of data as a school.txt file and put it on drive C.
Under the root directory.
2. Data input command load data local infile "C: // school.txt" into table name;
Note
Purpose: You 'd better copy the file to the [url = file: // MySQL // bin] // MySQL // bin [/url] Directory, use the use command to create the table.
.
V. Back up the database: (run the command in the DOS directory [url = file: // MySQL // bin] // MySQL // bin [/url)
1.
Export the entire database
The exported files are stored in the MySQL/bin directory by default.
Mysqldump-u username-P Database Name> exported file name
Mysqldump-u user_name-p123456 database_name> outfile_name. SQL
2.
Export a table
Mysqldump-u user name-P database name Table Name> exported file name
Mysqldump-u user_name-P database_name table_name> outfile_name. SQL
3.
Export a database structure
Mysqldump-u user_name-p-D-add-drop-Table database_name> outfile_name. SQL
-D No
-Add-drop-table added a drop table before each create statement.
4. Export with language Parameters
Mysqldump-uroot-p-default-character-set = Latin1-set-charset = GBK-Skip-opt database_name> outfile_name. SQL

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.