DOS command character (2) -- MySQL

Source: Internet
Author: User
Tags mysql host

1. Connect to MySQL.

1. Connect to MySQL on the remote host.

Mysql-h110.110.110.110-uroot-pabcd123

2. Exit MySQL command: exit (Press ENTER)

II.Display operation

1. display the data table structure:

Mysql>Describe table;

2. database creation:

Mysql>Create Database database name;

3. Delete databases and tables:

Mysql> drop database database name;

Mysql>Drop table name;

4. Clear records in the table:

Mysql>Delete from table name;

3. An instance for creating a database, creating a table, and inserting data

Mysql>Drop database if exists school; // Delete if school exists
Mysql>Create Database school; // create a database School
Mysql>Use school; // open the school library
Mysql>Create Table teacher // create table teacher
(
Id int (3) auto_increment not null primary key,
Name char (10) Not null,
Address varchar (50) default 'shenzhen ',
Year date
); // Table creation ends

// Insert fields as follows
Mysql>Insert into teacher values ('', 'glengang ', 'shenzhen Zhongyi', '2017-10-10 ');
Mysql>Insert into teacher values ('', 'jack', 'shenzhen Zhongyi ', '2017-12-23 ');

You can write the preceding command as is to school. SQL, copy it to c: \, and then:

Mysql-uroot-P password <c: \ school. SQL
4. modify a field

1. Modify the field type of a table and specify it as null or non-empty.
MySQL> Alter table table name change field Name field New Name field type [whether to allow non-null];
MySQL> Alter table table name Modify Field Name field type [whether to allow non-null];

2. Add a field

MySQL> Alter table uch_pai add zxgname varchar (30) null default 'aaa ';

Supplement: What is the size of the int type? Only char and varchar need the size.

5. Change the password.

1. Example 1: Add a password ab12 to the root user. First, enter the directory mysqlbin in DOS, and then type the following command

Mysqladmin-uroot-Password ab12

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 root password to djg345.

Mysqladmin-uroot-pab12 password djg345

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

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 User Added 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 \"\";

VII. Back up the database: (The command is executed in the \ mysql \ bin directory of DoS)

Mysqldump-uxxx-pxxx -- database DDD -- skip-lock-tables> C:/New. SQL

Here,-Skip-lock-tables is used to skip the locked table.

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.