Adding, deleting, modifying and checking the database building of Mysql database

centos7 install mysql

[root@localhost ~]# yum -y install mariadb mariadb-server

Start mysql

[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Create a database

MariaDB [(none)]> create database ku;
Query OK, 1 row affected (0.00 sec)

Create a UTF8 database

MariaDB [(none)]> create database ku1 character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

View all libraries

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ku                 |
| ku1                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)

Delete database

MariaDB [(none)]> drop database ku;  
Query OK, 0 rows affected (0.00 sec)

Create three types of tables: innodb, myisam, memory

先进入一个数据库
MariaDB [(none)]> use ku1;
Database changed
MariaDB [ku1]> create table test1(id int(10),name varchar(10)) engine=mylsam;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

MariaDB [ku1]> create table test2(id int(10),name varchar(10)) engine=innodb;
Query OK, 0 rows affected (0.00 sec)

MariaDB [ku1]> create table test3(id int(10),name varchar(10)) engine=memory;
Query OK, 0 rows affected (0.00 sec)

View table structure

MariaDB [ku1]> desc test2;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(10)     | YES  |     | NULL    |       |
| name  | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

Delete table

MariaDB [ku1]> drop table test1;
Query OK, 0 rows affected (0.00 sec)

Routine operation: increase

MariaDB [ku1]> insert into test2 values(1,"小红花");
Query OK, 1 row affected (0.00 sec)
MariaDB [ku1]> insert into test2 values(2,"小绿花");
Query OK, 1 row affected (0.00 sec)

Routine operation: delete

Delete all data in the table:

MariaDB [ku1]> delete from test2;
Query OK, 1 row affected (0.00 sec)

Routine operation: change

MariaDB [ku1]> update test2 set name="小黄花" where name="小红花";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Routine operation: check

View the data of the entire table:

MariaDB [ku1]> select * from test2;
+------+-----------+
| id   | name      |
+------+-----------+
|    1 | 小黄花    |
|    2 | 小绿花    |
+------+-----------+
2 rows in set (0.00 sec)

Specify id to view:

MariaDB [ku1]> select * from test2 where id=2;
+------+-----------+
| id   | name      |
+------+-----------+
|    2 | 小绿花    |
+------+-----------+
1 row in set (0.00 sec)

Specify name to view:

MariaDB [ku1]> select * from test2 where name="小黄花";
+------+-----------+
| id   | name      |
+------+-----------+
|    1 | 小黄花    |
+------+-----------+
1 row in set (0.00 sec)

Guess you like

Origin blog.csdn.net/Q274948451/article/details/109350896