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
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 var char( 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 | var char( 60 ) | NO | UNI | | |
| ptime | int ( 11 ) | NO | MUL | 0 | |
| content | text | YES | | NULL | |
+---------+------------------+------+-----+---------+----------------+
4 rows in set ( 0.00 sec)
|