6、数据库常见管理应用


mysql建库的字符集为latin1,客户端的字符集为utf8;

6.1、创建数据库:

1、命令语法:

create database <数据库名称>; #注意数据库名不能以数字开头;

2、命令:

mysql> create database lc;

Query OK, 1 row affected (0.11 sec)

mysql> show databases;

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

| Database |

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

| information_schema |

| lc |

| mysql |

| performance_schema |

| wordpress |

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

5 rows in set (0.19 sec)

6.2、显示数据库:

1、显示所有数据库:

mysql> show databases;

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

| Database |

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

| information_schema |

| lc |

| lc1 |

| lc2 |

| mysql |

| performance_schema |

| wordpress |

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

7 rows in set (0.00 sec)

2、显示相似数据库:

mysql> show databases like '%lc%' ;

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

| Database (%lc%) |

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

| lc |

| lc1 |

| lc2 |

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

3 rows in set (0.00 sec)

6.3、删除数据库:

mysql> drop database lc2;

Query OK, 0 rows affected (0.00 sec)

mysql> show databases like '%lc2%';

Empty set (0.00 sec)

6.4、连接数据库(相当于linux中cd命令):

mysql> use lc;

Database changed

6.5、显示当前连接的数据库(类似于pwd、whoami命令);

mysql> select database();

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

| database() |

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

| lc |

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

1 row in set (0.00 sec)

6.6、查看当前登录的用户:

mysql> select user();

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

| user() |

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

| root@localhost |

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

1 row in set (0.00 sec)

6.7、查看当前数据库的版本:

mysql> select version();

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

| version() |

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

| 5.5.62 |

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

1 row in set (0.00 sec)

6.8、查看当前的时间:

mysql> select now();

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

| now() |

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

| 2019-02-18 16:05:37 |

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

1 row in set (0.00 sec)

6.9、显示连接数据库的表:

mysql> show tables;

Empty set (0.00 sec)

6.10、删除mysql系统多余的账号;

mysql> drop user ''@'localhost'; #主机名是大写的时候会删除不了用户,

#需要是使用下面的删除方法;

Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where user='';

Query OK, 1 row affected (0.00 sec)

6.11、建表:

1、语法:

create table <表名> (

<字段名1> <类型1>,

......

<字段名n> <类型n>

);

#建表时使用的数据库指定的编码集;

create table student1 (

id int(16) not null,

name varchar(20) not null,

age int(2) not null,

dept varchar(20) default null

);

mysql> show tables;

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

| Tables_in_lc |

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

| student |

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

1 row in set (0.00 sec)

6.12、mysql表的类型:

你可能感兴趣的:(6、数据库常见管理应用)