

1.mariadb源配置
[root@localhost yum.repos.d]# vim mariadb.repo
[root@localhost yum.repos.d]# cat mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
[root@localhost yum.repos.d]# yum clean all && yum makecache
2.mariadb安装
[root@localhost yum.repos.d]# yum install MariaDB-server MariaDB-client -y

[root@localhost yum.repos.d]# systemctl start mariadb
3.2mariadb进程查看
[root@localhost yum.repos.d]# netstat -ntlp |grep 3306
[root@localhost yum.repos.d]# mysql_secure_installation

Switch to unix_socket authentication [Y/n]
输入y
Change the root password? [Y/n] y
密码:uK8F8cECIDvv


MariaDB [(none)]> set password = PASSWORD('hsz123'); 修改mysql密码
MariaDB [(none)]> create database mytest charset=utf8; 创建数据库mytest,并指定默认字符集为utf8
MariaDB [(none)]> use mytest; 切换数据库
Database changed
MariaDB [mytest]> create table mytest(id int,name char(32)); 创建表
Query OK, 0 rows affected (0.014 sec)
MariaDB [mytest]> desc mytest; 查看表结构,有id,name, 其中int和char表示数据类型
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(32) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.009 sec)

插入(增加)数据:
MariaDB [mytest]> insert into mytest(id,name) values(1,"zero"),(2,"one"); 给表名为mytest的表 插入两条数据
MariaDB [mytest]> select id,name from mytest; 查询id和name字段的内容
MariaDB [mytest]> select * from mytest; 查询表的全部内容
删除数据:
MariaDB [mytest]> delete from mytest where id=2; 删除mytest表id为2字段的数据
修改数据:

MariaDB [mytest]> update mytest set name="ten" where id=1; 修改name字段数据为“ten”,对象为id字段为1的

创建用户和密码
1.创建用户:
# 指定ip:192.118.1.1的mjj用户登录
create user 'alex'@'192.118.1.1' identified by '123';
# 指定ip:192.118.1.开头的mjj用户登录
create user 'alex'@'192.118.1.%' identified by '123';
# 指定任何ip的mjj用户登录
create user 'alex'@'%' identified by '123';
查询zero用户的数据库如下所示:
[root@localhost ~]# mysql -uzero -pzero
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.4.15-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.001 sec)

