Mysql Command Line Operation statements, mysql command line statements

Source: Internet
Author: User
Tags mysql command line

Mysql Command Line Operation statements, mysql command line statements

First, start and stop the mysql Service

Net stop mysql
Net start mysql

Second, log on to mysql

Syntax: mysql-u user name-p User Password

Enter the mysql-uroot-p command, press enter and prompt you to enter the password, enter 12345, and then press enter to enter mysql. The mysql prompt is:
Mysql>

Note: If you are connecting to another machine, you need to add a parameter-h Machine IP address.

Third, add new users

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

For example, you can add a user user1 with the password password1 so that the user can log on to the machine and have the permission to query, insert, modify, and delete all databases. First

Run the following command to connect the root user to mysql:

Grant select, insert, update, delete on *. * to user1 @ localhost Identified by "password1 ";

If you want the user to log on to mysql on any machine, change localhost to "% ".

If you do not want user1 to have a password, you can run another command to remove the password.

Grant select, insert, update, delete on mydb. * to user1 @ localhost identified "";

Step 4: operate databases

Log on to mysql and run the following commands at the mysql prompt. Each Command ends with a semicolon.
1. display the Database List.

Show databases;
By default, two databases are available: mysql and test. Mysql inventory contains the mysql system and user permission information. We change the password and add users, in fact, this database is actually operated.

2. display the data tables in the database:
Use mysql;
Show tables;

3. display the data table structure:

Describe table name;

4. Create and delete databases:

Create database name;
Drop database name;
5. Create a table:

Use Database Name;
Create table Name (Field List );
Drop table name;

6. Clear the table records:

Delete from table name;
7. display the records in the table:

Select * from table name;

Step 5: export and import data

1. Export data:

Mysqldump -- opt test> mysql. test
Export the database test database to the mysql. test file, which is a text file
For example, mysqldump-u root-p123456 -- databases dbname> mysql. dbname
Export the database dbname to the mysql. dbname file.

2. import data:

Mysqlimport-u root-p123456 <mysql. dbname.
No need to explain it.

3. Import text data to the database:

Field data of text data is separated by the tab key.
Use test;
Load data local infile "file name" into table name;

1: Use the SHOW statement to find out the current database on the server:
Mysql> show databases;

2: Create a database MYSQLDATA
Mysql> create database mysqldata;

3: select the database you created

Mysql> use mysqldata; (when you press the Enter key to see Database changed, the operation is successful !)

4: view the tables in the current database

Mysql> show tables;

5. Create a database table

Mysql> create table mytable (name VARCHAR (20), sex CHAR (1 ));

6: display the table structure:

Mysql> describe mytable;

7. Add records to the table

Mysql> insert into MYTABLE values ("hyq", "M ");

8: load data into database tables in text mode (for example, D:/mysql.txt)

Mysql> load data local infile "D:/mysql.txt" into table mytable;

9: import the. SQL FILE command (for example, D:/mysql. SQL)

Mysql> use database;
Mysql> source d:/mysql. SQL;

10: delete a table

Mysql> drop table mytable;

11: Clear the table

Mysql> delete from MYTABLE;

12: Update table data

Mysql> update MYTABLE set sex = "f" where name = 'hyq ';

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.