centos7 安装mysql
[root@localhost ~]# yum -y install mariadb mariadb-server
启动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)]>
mysql基础操作
- centos7 安装mysql
- 启动mysql
-
- 创建一个数据库
- 创建一个UTF8的数据库
- 查看所有库
- 删除数据库
- 创建表 表的三种类型:innodb,myisam,memory
-
- 查看表结构
- 删除表
- 常规操作:增
- 常规操作:删
- 常规操作:改
- 常规操作:查
创建一个数据库
MariaDB [(none)]> create database ku;
Query OK, 1 row affected (0.00 sec)
创建一个UTF8的数据库
MariaDB [(none)]> create database ku1 character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
查看所有库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ku |
| ku1 |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
删除数据库
MariaDB [(none)]> drop database ku;
Query OK, 0 rows affected (0.00 sec)
创建表 表的三种类型: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)
查看表结构
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)
删除表
MariaDB [ku1]> drop table test1;
Query OK, 0 rows affected (0.00 sec)
常规操作:增
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)
常规操作:删
删除表的全部数据:
MariaDB [ku1]> delete from test2;
Query OK, 1 row affected (0.00 sec)
常规操作:改
MariaDB [ku1]> update test2 set name="小黄花" where name="小红花";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
常规操作:查
查看整张表的数据:
MariaDB [ku1]> select * from test2;
+------+-----------+
| id | name |
+------+-----------+
| 1 | 小黄花 |
| 2 | 小绿花 |
+------+-----------+
2 rows in set (0.00 sec)
指定id来查看:
MariaDB [ku1]> select * from test2 where id=2;
+------+-----------+
| id | name |
+------+-----------+
| 2 | 小绿花 |
+------+-----------+
1 row in set (0.00 sec)
指定name来查看:
MariaDB [ku1]> select * from test2 where name="小黄花";
+------+-----------+
| id | name |
+------+-----------+
| 1 | 小黄花 |
+------+-----------+
1 row in set (0.00 sec)