MYSQL-MySQL tutorial

Source: Internet
Author: User
Tags mysql host mysql tutorial
Summarize and organize MYSQL-related operation command test environment: mysql 5.0.45
[Note: you can use mysql> select version (); in mysql to view the database VERSION]
Finishing up: Webjx. Com
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, then enter the directory mysqlin, then type the command mysql-u root-p, and press enter to prompt you to enter the password. note that there can be space or space before the user name, but there must be no space before the password; otherwise, you can re-enter the password.
If you have just installed MYSQL, the super user root has no password, so press enter to enter MYSQL. the MYSQL prompt is: mysql>
2. connect to MYSQL on the remote host. Assume that the IP address of the remote host is 110.110.110.110, the user name is root, and the password is abcd123. Enter the following command:
Mysql-h110.110.110.110-u root-p 123)
3. exit MYSQL command: exit (press enter)
2. change the password.
Format: mysqladmin-u username-p old password new password
1. add a password ab12 to the root user. First enter the directory mysqlin under DOS, and then type the following command
Mysqladmin-u root-password ab12
Note: Because the root account does not have a password at the beginning, the old-p password can be omitted.
2. change the root password to djg345.
Mysqladmin-u root-p ab12 password djg345
3. add new users.
(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"
1. add a user named "test1" with the password "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 do whatever he wants for your data. See solution 2.
2. add a user named "test2" with the password "abc" so that the user can only log on to localhost and query, insert, modify, and delete the database mydb (localhost refers to the local host, that is, the host of the MYSQL database ),
In this way, the user knows the password of test2 and cannot directly access the database from the internet. he can only access the database through the web page on the MYSQL host.
Grant select, insert, update, delete on mydb. * to [email = test2 @ localhost] test2 @ localhost [/email] 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 [email = test2 @ localhost] test2 @ localhost [/email] identified by "";
Next I will perform database operations in MYSQL. 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 into several lines, and then use a semicolon as the end sign to complete the operation.
2. you can use the cursor to bring up or down the previous commands.
II. display commands
1. display the list of databases on the current database server:
Mysql> show databases;
Note: the mysql database contains the MYSQL system information. we change the password and add new users to use this database for operations.
2. display data tables in the database:
Mysql> USE database name;
Mysql> show tables;
3. display the data table structure:
Mysql> DESCRIBE table name;
4. create a database:
Mysql> create 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 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 ");

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.