Use the command line to operate mysql Databases

Source: Internet
Author: User
Familiar with the simple use of command lines to operate mysql database Note: Only one user is allowed in phpmyadmin, and rootlocalhost introduces simple commands to connect to database 1. you can directly open the command line, WINR, And Enter cmd in the command line and enter: 1mysql-hlocalhost-uroot-p password or (this can be protected)

Familiar with the simple use of command lines to operate mysql database Note: Only one user is allowed in phpmyadmin, and rootlocalhost introduces simple commands to connect to database 1. you can directly open the command line, WINR, And Enter cmd in the command line and enter: 1 mysql-h localhost-u root-p password or (this can be protected)

 Familiar with simple use of command lines to operate mysql Databases

Note:

Only one user is allowed in phpmyadmin, root localhost

The following describes simple commands.

Connect to database

1. You can directly open the command line, WIN + R, and Enter cmd

Enter:


1

Mysql-h localhost-u root-p Password

Or (this can protect the password. You cannot use the up or down key to view previous commands)

1

2

3

mysql -h localhost -u root -p

Password:*****

Command: \ s displays basic information about the database

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

mysql> \s

--------------

mysql Ver 14.12 Distrib 5.0.45, for Win32 (ia32)

Connection id: 2

Current database:

Current user: root@localhost

SSL: Not in use

Using delimiter: ;

Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL)

Protocol version: 10

Connection: localhost via TCP/IP

Server characterset: utf8

Db characterset: utf8

Client characterset: utf8

Conn. characterset: utf8

TCP port: 3306

Uptime: 44 min 5 sec

Threads: 1 Questions: 4 Slow queries: 0 Opens: 12 Flush tables: 1 Open tabl

es: 0 Queries per second avg: 0.002

Command: exit; exit DATABASE Command Line

1

2

mysql> exit;

Bye

Command: \ c; when an error is accidentally entered

Mysql> dasf
->
->
->
->
->
->

You can use the \ c command to exit the current

1

2

3

4

5

6

7

8

mysql> dasf

->

->

->

->

->

-> \c

mysql>

Command: show databases; displays mysql databases

1

2

3

4

5

6

7

8

9

10

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| phpmyadmin |

| test |

+--------------------+

4 rows in set (0.13 sec)

Command: select a database for use. Here \ c is used to switch the database. The command can view the test information of the current database.

1

2

mysql> use test;

Database changed

Command: caret table

Create table [if not exists] table Name (

Field name 1 type [attribute] [Index],

Field name 2 type [attribute] [Index],

...

);

1

2

3

4

5

6

7

8

9

mysql> create table article1(

-> id int unsigned not null auto_increment,

-> title varchar(60) not null default '' unique,

-> ptime int not null default 0,

-> content text,

-> key article_ptime(ptime),

-> primary key(id)

-> );

Query OK, 0 rows affected (0.20 sec)


Command: desc display table structure

1

2

3

4

5

6

7

8

9

10

mysql> desc article1;

+---------+------------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+---------+------------------+------+-----+---------+----------------+

| id | int(10) unsigned | NO | PRI | NULL | auto_increment |

| title | varchar(60) | NO | UNI | | |

| ptime | int(11) | NO | MUL | 0 | |

| content | text | YES | | NULL | |

+---------+------------------+------+-----+---------+----------------+

4 rows in set (0.00 sec)

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.