MySQL usage highlights

Source: Internet
Author: User
Tags mysql host

 

1) connect to MySQL:

 
Format: mysql-H host address-u user name-P User Password

1. Example 1: connect to MySQL on the local machine

 
Mysql-uroot-P. Press enter and you will be prompted to lose the password,
 
If you have just installed MySQL, the Super User Root does not have a password, so press enter to enter MySQL
 
2. Example 2: connect to MySQL on the remote host
 
Assume that the IP address of the remote host is 10.0.0.1, the user name is root, and the password is 123. Enter the following command:
 
Mysql-h10.0.0.1-uroot-p123
 
(Note: you do not need to add spaces for u and root. The same applies to others)

3. Exit MySQL Command

 
Exit (Press ENTER)

(2) Change the password:

 
Format: mysqladmin-u username-P old Password New Password

1. Example 1: Add a 123 password to the root user.

 

Mysqladmin-uroot-Password 123

 
Note: because the root account does not have a password at the beginning, the old-P password can be omitted.

2. Example 2: change the password of root to 456.

Mysqladmin-uroot-pab12 password 456

(3) Add a new user: (Note: Unlike the above, the following commands in the MySQL environment are followed by a semicolon as the command Terminator)

 
Format: grant select on database. * To username @ login host identified by "password"
 
Example 1: Add a user named "test1" with the password "ABC" so that the user 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 test1 @ "%" identified by "ABC"; however, the added user in Example 1 is 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 do whatever he wants for your data. For the solution, see Example 2.
 
Example 2: Add a user named "Test2" with the password "ABC" so that the user can only log on to localhost, you can also query, insert, modify, and delete the database mydb (localhost refers to the local host, that is, the host where the MySQL database is located), so that the user knows the password of Test2, he cannot access the database directly from the Internet, but can only access the database through the web pages on the MySQL host. Grant select, insert, update, delete on mydb. * To Test2 @ localhost identified by "ABC ";
 
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 Test2 @ localhost identified "";

(4) display commands

1. display the Database List:

Show databases; At the beginning, there were only two databases: MySQL and test. The MySQL database contains the MySQL system information. We change the password and add new users to use this database for operations.

2. display the data tables in the database:

 
Use MySQL; // open the database
 
Show tables;

3. display the data table structure:

 
Describe table name;

4. database creation:

 
Create Database database name;

5. Create a table:

 
Use Database Name; Create Table Name (field setting list );

6. Delete databases and tables:

 
Drop database database name; drop table name;

7. Clear records in the table:

 
Delete from table name;

8. Display records in the table:

 
Select * from table name;
 
4) Other commands
 

Run the SQL FILE command in MySQL.

 

Mysql> Use Database

 

Mysql> source/root/db. SQL;

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.