mysql的简单操作
一、查看数据库
SHOW DATABASES;
例如:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
二、创建数据库
CREATE DATABASE 数据库名称;
例如:
MariaDB [mysql]> create database han;
Query OK, 1 row affected (0.01 sec)
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| han |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
三、进入数据库
USE 数据库名称;
例如:
MariaDB [mysql]> use han;
Database changed
四、查看表
SHOW TABLES;
例如:
MariaDB [han]> show tables;
+---------------+
| Tables_in_han |
+---------------+
| redhat |
+---------------+
1 row in set (0.00 sec)
五、新建数据表
CREATE TABLE 数据表名称(
->列名称1 数据类型 not null,
->列名称2 数据类型 not null,
. . . ,
. . . ,
. . .
->);
MariaDB [han]> create table redhat(
-> user varchar(50) not null,
-> passwd varchar(50) not null
-> );
Query OK, 0 rows affected (0.02 sec)
六、查看数据表内容
SELECT * FORM 表名称;
例如:
MariaDB [han]> select * from redhat;
+------+--------+
| user | passwd |
+------+--------+
| user | 123 |
+------+--------+
1 row in set (0.00 sec)
七、表中添加数据
INSERT INTO 表名称 VALUES(‘第一列数据’,‘第二列数据’);
例如:
MariaDB [han]> insert into redhat values(‘user‘,‘123‘)
-> ;
Query OK, 1 row affected (0.00 sec)
八、删除表中数据
DELETE FROM 表名称 WHERE 列名=‘数据’;
例如:
MariaDB [han]> select * from redhat;
+------+--------+
| user | passwd |
+------+--------+
1 row in set (0.00 sec)
九、删除表
DROP TABLE 表名称;
例如:
MariaDB [han]> drop table redhat
-> ;
Query OK, 0 rows affected (0.01 sec)
十、删除数据库
DROP DATABASE 数据库名称;
例如:
MariaDB [han]> drop database han;
Query OK, 0 rows affected (0.05 sec)
原文地址:https://www.cnblogs.com/majinhai/p/9425433.html