[root@localhost ~]# yum -y install mariadb mariadb-server
root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# mysql -uroot -p123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.68-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 database baobao charset utf8;
ERROR 1007 (HY000): Can't create database 'baobao'; database exists
MariaDB [(none)]> create database baobao charset utf8;
ERROR 1007 (HY000): Can't create database 'baobao'; database exists
MariaDB [(none)]> create database baobao charset utf8;
ERROR 1007 (HY000): Can't create database 'baobao'; database exists
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| aoyun |
| baobao |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
MariaDB [(none)]> use baobao
Database changed
MariaDB [baobao]> create table aoyun(
-> id int(1) primary key auto_increment not null unique,
-> 国家 varch(12),
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'varch(12),' at line 3
MariaDB [baobao]> create table aoyun( id int(1) primary key auto_increment not null unique, 国家 varchar(12), 金 varchar(12), 银 varchar(12), 铜 varchar(12), 总数 varchar(12));
Query OK, 0 rows affected (0.02 sec)
MariaDB [baobao]> show aoyun;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'aoyun' at line 1
MariaDB [baobao]> desc aoyun;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(1) | NO | PRI | NULL | auto_increment |
| 国家 | varchar(12) | YES | | NULL | |
| 金 | varchar(12) | YES | | NULL | |
| 银 | varchar(12) | YES | | NULL | |
| 铜 | varchar(12) | YES | | NULL | |
| 总数 | varchar(12) | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
MariaDB [baobao]> insert into aoyun values(1,"美国","39","41","33","113");
Query OK, 1 row affected (0.00 sec)
MariaDB [baobao]> select * from aoyun;
+----+--------+------+------+------+--------+
| id | 国家 | 金 | 银 | 铜 | 总数 |
+----+--------+------+------+------+--------+
| 1 | 美国 | 39 | 41 | 33 | 113 |
+----+--------+------+------+------+--------+
1 row in set (0.00 sec)
MariaDB [baobao]> insert into aoyun values(1,"中国","38","32","18","88");
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
MariaDB [baobao]> insert into aoyun values(0,"中国","38","32","18","88");
Query OK, 1 row affected (0.00 sec)
MariaDB [baobao]> insert into aoyun values(0,"日本","27","14","17","58");
Query OK, 1 row affected (0.01 sec)
MariaDB [baobao]> insert into aoyun values(0,"英国","22","21","22","65");
Query OK, 1 row affected (0.00 sec)
MariaDB [baobao]> insert into aoyun values(0,"俄罗斯奥委会","20","28","23","71");
Query OK, 1 row affected (0.00 sec)
MariaDB [baobao]> insert into aoyun values(0,"澳大利亚","17","7","22","46");
Query OK, 1 row affected (0.00 sec)
MariaDB [baobao]> select * from aoyun;
+----+--------------------+------+------+------+--------+
| id | 国家 | 金 | 银 | 铜 | 总数 |
+----+--------------------+------+------+------+--------+
| 1 | 美国 | 39 | 41 | 33 | 113 |
| 2 | 中国 | 38 | 32 | 18 | 88 |
| 3 | 日本 | 27 | 14 | 17 | 58 |
| 4 | 英国 | 22 | 21 | 22 | 65 |
| 5 | 俄罗斯奥委会 | 20 | 28 | 23 | 71 |
| 6 | 澳大利亚 | 17 | 7 | 22 | 46 |
+----+--------------------+------+------+------+--------+
6 rows in set (0.00 sec)
MariaDB [baobao]> select * from aoyun where 国家='中国';
+----+--------+------+------+------+--------+
| id | 国家 | 金 | 银 | 铜 | 总数 |
+----+--------+------+------+------+--------+
| 2 | 中国 | 38 | 32 | 18 | 88 |
+----+--------+------+------+------+--------+
1 row in set (0.00 sec)
MariaDB [baobao]> select * from aoyun order by 金 desc;
+----+--------------------+------+------+------+--------+
| id | 国家 | 金 | 银 | 铜 | 总数 |
+----+--------------------+------+------+------+--------+
| 1 | 美国 | 39 | 41 | 33 | 113 |
| 2 | 中国 | 38 | 32 | 18 | 88 |
| 3 | 日本 | 27 | 14 | 17 | 58 |
| 4 | 英国 | 22 | 21 | 22 | 65 |
| 5 | 俄罗斯奥委会 | 20 | 28 | 23 | 71 |
| 6 | 澳大利亚 | 17 | 7 | 22 | 46 |
+----+--------------------+------+------+------+--------+
6 rows in set (0.01 sec)
MariaDB [baobao]> update aoyun set 金='7' where 国家='日本';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [baobao]> select * from aoyun;
+----+--------------------+------+------+------+--------+
| id | 国家 | 金 | 银 | 铜 | 总数 |
+----+--------------------+------+------+------+--------+
| 1 | 美国 | 39 | 41 | 33 | 113 |
| 2 | 中国 | 38 | 32 | 18 | 88 |
| 3 | 日本 | 7 | 14 | 17 | 58 |
| 4 | 英国 | 22 | 21 | 22 | 65 |
| 5 | 俄罗斯奥委会 | 20 | 28 | 23 | 71 |
| 6 | 澳大利亚 | 17 | 7 | 22 | 46 |
+----+--------------------+------+------+------+--------+
6 rows in set (0.00 sec)
MariaDB [baobao]> select * from aoyun;
+----+--------------------+------+------+------+--------+
| id | 国家 | 金 | 银 | 铜 | 总数 |
+----+--------------------+------+------+------+--------+
| 1 | 美国 | 39 | 41 | 33 | 113 |
| 2 | 中国 | 38 | 32 | 18 | 88 |
| 3 | 日本 | 7 | 14 | 17 | 58 |
| 4 | 英国 | 22 | 21 | 22 | 65 |
| 5 | 俄罗斯奥委会 | 20 | 28 | 23 | 71 |
| 6 | 澳大利亚 | 17 | 7 | 22 | 46 |
+----+--------------------+------+------+------+--------+