当前位置:   article > 正文

mariadb数据库从入门到精通_怎么全面的学习mariadb数据库的知识

怎么全面的学习mariadb数据库的知识

mariadb数据库的安装以及安全初始化



一、实验前提

实验环境:yum仓库搭建好
mariadb 是当前流行的Mysql数据库的分支
Mysql原先SUN公司(java)被Orical收购了
Mysql开源免费,所以企业当中的核心数据库是Orical,其余是Mysql
mariadb是Mysql数据库的一个分支


二、mariadb数据库的安装

1.数据库的安装

[root@server15 ~]# yum serach mariadb
  • 1

在这里插入图片描述

[root@server15 yum.repos.d]# yum install mariadb-server.x86_64 -y
  • 1
[root@server15 yum.repos.d]# rpm -ql mariadb-server 
查看它在系统里面安装的东西
/var/lib/mysql  其中这个为它的数据目录
/etc/my.cnf.d/server.cnf 主配置文件
/usr/lib/systemd/system/mariadb.service 服务的启动脚本
  • 1
  • 2
  • 3
  • 4
  • 5
[root@server15 yum.repos.d]# systemctl enable --now mariadb.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
启动服务
  • 1
  • 2
  • 3
[root@server15 yum.repos.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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 |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> quit
Bye
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

三、mariadb数据库安全初始化

由于数据库的登陆不需要密码所以不安全,我们要安全初始化。


3.1 设定数据库基本的安全初始化

[root@server15 yum.repos.d]# mysql_secure_installation  初始化脚本
Enter current password for root (enter for none):   当前数据库管理员的密码,无密码直接回车
Set root password? [Y/n] Y                   设定数据库管理员密码
New password: 
Re-enter new password: 
Password updated successfully!
 ... Success!
Remove anonymous users? [Y/n] y   
 ... Success!         移除匿名用户登陆
Disallow root login remotely? [Y/n] y  
 ... Success!         移除管理员远程登陆
Remove test database and access to it? [Y/n] Y 
 ... Success!         移除测试库
Reload privilege tables now? [Y/n] y    
 ... Success!         刷新数据库
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

密码登陆

[root@server15 yum.repos.d]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.60-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)]> quit
Bye
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

默认情况下数据库对外开放端口,开放了,容易被攻击。一般在企业中要关闭

[root@server15 yum.repos.d]# netstat -antlupe | grep mysql
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      27         31978      3768/mysqld     
  • 1
  • 2

3.2关闭对外开放端口

[root@server15 yum.repos.d]# vim /etc/my.cnf.d/server.cnf 
编辑主配置文件

  • 1
  • 2
  • 3

在这里插入图片描述
关闭数据库网络端口

当设定完成后端口关闭

[root@server15 yum.repos.d]# systemctl restart mariadb.service 
[root@server15 yum.repos.d]# netstat -antlupe | grep mysql
  • 1
  • 2

END

系列文章目录

数据库的查询2


一、查看数据库

[root@server15 mnt]# mysql -uroot -p
MariaDB [(none)]> SHOW DATABASES; 查看有什么库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

二、进入库并且查看数据库中的表

MariaDB [(none)]> USE mysql;      进入这个库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
  • 1
  • 2
  • 3
  • 4
MariaDB [mysql]> SHOW TABLES;    查看表
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

三、查看数据库里所有表的名字

MariaDB [mysql]> SHOW TABLES FROM mysql;
查看mysql库里面所有表的名字
  • 1
  • 2

四、查看数据库里所有表的名字

MariaDB [mysql]> SELECT * FROM user;
查看user表里面的所有内容
  • 1
  • 2

在这里插入图片描述

4.1表里面的字段

表里面的字段
在这里插入图片描述

4.2查看表里面的字段

MariaDB [mysql]> SELECT Host,User,Password FROM user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| 127.0.0.1 | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| ::1       | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

查看表里面的字段可以接条件

MariaDB [mysql]> SELECT Host,User,Password FROM user WHERE User='root' and Host='localhost';
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

.表示分级

MariaDB [(none)]> SELECT Host,User,Password FROM mysql.user WHERE User='root' and Host='localhost';
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

END

系列文章目录

数据库的建立3


一、新建一个库

[root@server15 mnt]# mysql -uroot -p
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> CREATE DATABASE westos;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westos             |
+--------------------+
4 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

二、新建一个表

MariaDB [(none)]> USE westos;
Database changed
MariaDB [westos]> SHOW TABLES;
Empty set (0.00 sec)
MariaDB [westos]> CREATE TABLE westos.linux (
    -> username varchar(6) not null,
    -> password varchar(30) not null
    -> );
Query OK, 0 rows affected (0.44 sec)

MariaDB [westos]> SHOW TABLES;
+------------------+
| Tables_in_westos |
+------------------+
| linux            |
+------------------+
1 row in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

三、查看表的结构

MariaDB [westos]> DESC westos.linux;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(6)  | NO   |     | NULL    |       |
| password | varchar(30) | NO   |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

四、给表里面插入数据

MariaDB [westos]> INSERT INTO westos.linux VALUES ('lee',123)
    -> ;
Query OK, 1 row affected (0.04 sec)

MariaDB [westos]> DESC westos.linux;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(6)  | NO   |     | NULL    |       |
| password | varchar(30) | NO   |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

MariaDB [westos]> SELECT * FROM westos.linux
    -> ;
+----------+----------+
| username | password |
+----------+----------+
| lee      | 123      |
+----------+----------+
1 row in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

五、同时向表中插入多个数据

MariaDB [westos]> INSERT INTO westos.linux VALUES ('lee1','123'),('lee2','123');
Query OK, 2 rows affected (0.40 sec)
Records: 2  Duplicates: 0  Warnings: 0

MariaDB [westos]> SELECT * FROM westos.linux
    -> ;
+----------+----------+
| username | password |
+----------+----------+
| lee      | 123      |
| lee1     | 123      |
| lee2     | 123      |
+----------+----------+
3 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

END

系列文章目录

数据库密码的破解5


一、更改密码(知道原始密码)

[root@server15 mysql]# mysqladmin -uroot -p password 
Enter password: 
New password: 
Confirm new password: 
  • 1
  • 2
  • 3
  • 4

二、更改密码(不知道原先密码)

1.跳过授权表进入数据库

[root@server15 mysql]# mysqld_safe --skip-grant-tables & 
跳过授权表打开数据库 &后台运行
[2] 5479
[root@server15 mysql]# 210726 18:12:13 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
210726 18:12:13 mysqld_safe A mysqld process already exists
[root@server15 mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.60-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)]> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

2.修改密码

在这里插入图片描述
3.更改里面的这个字段

在这里插入图片描述

MariaDB [(none)]> UPDATE mysql.user SET authentication_string=password('123') WHERE User='root';rhel8
MariaDB [(none)]> UPDATE mysql.user SET Password=password('123') WHERE User='root';   rhel7
  • 1
  • 2

4.查看mysql的所有进程并且关闭掉

[root@server15 mysql]# ps aux | grep mysql
root      5297  0.0  0.1 113312  1632 pts/0    S    18:10   0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql     5455  0.0  8.6 970848 88272 pts/0    Sl   18:10   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root      5620  0.0  0.0 112708   972 pts/0    R+   18:20   0:00 grep --color=auto mysql
[root@server15 mysql]# kill -9 5297
[root@server15 mysql]# kill -9 5455
ps aux | grep mysql
root      5624  0.0  0.0 112708   976 pts/0    R+   18:22   0:00 grep --color=auto mysql 这个是grep的进程
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

5.更改完成

[root@server15 mysql]# systemctl start mariadb.service 
[root@server15 mysql]#  mysql -uroot -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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)]> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

END

系列文章目录

数据库密码的破解5


一、更改密码(知道原始密码)

[root@server15 mysql]# mysqladmin -uroot -p password 
Enter password: 
New password: 
Confirm new password: 
  • 1
  • 2
  • 3
  • 4

二、更改密码(不知道原先密码)

1.跳过授权表进入数据库

[root@server15 mysql]# mysqld_safe --skip-grant-tables & 
跳过授权表打开数据库 &后台运行
[2] 5479
[root@server15 mysql]# 210726 18:12:13 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
210726 18:12:13 mysqld_safe A mysqld process already exists
[root@server15 mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.60-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)]> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

2.修改密码

在这里插入图片描述
3.更改里面的这个字段

在这里插入图片描述

MariaDB [(none)]> UPDATE mysql.user SET authentication_string=password('123') WHERE User='root';rhel8
MariaDB [(none)]> UPDATE mysql.user SET Password=password('123') WHERE User='root';   rhel7
  • 1
  • 2

4.查看mysql的所有进程并且关闭掉

[root@server15 mysql]# ps aux | grep mysql
root      5297  0.0  0.1 113312  1632 pts/0    S    18:10   0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql     5455  0.0  8.6 970848 88272 pts/0    Sl   18:10   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root      5620  0.0  0.0 112708   972 pts/0    R+   18:20   0:00 grep --color=auto mysql
[root@server15 mysql]# kill -9 5297
[root@server15 mysql]# kill -9 5455
ps aux | grep mysql
root      5624  0.0  0.0 112708   976 pts/0    R+   18:22   0:00 grep --color=auto mysql 这个是grep的进程
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

5.更改完成

[root@server15 mysql]# systemctl start mariadb.service 
[root@server15 mysql]#  mysql -uroot -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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)]> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

END

系列文章目录

如何重新安装数据库6


重新安装数据库

企业中不能重新安装数据库

[root@server15 mysql]# systemctl stop mariadb.service 
[root@server15 mysql]# rm -fr /var/lib/mysql/
[root@server15 mysql]# yum reinstall mariadb-server.x86_64 -y
  • 1
  • 2
  • 3
[root@server15 mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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)]> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

END

系列文章目录

数据库的用户建立和授权7


一、查看数据库用户

MariaDB [(none)]> SELECT Host,User FROM mysql.user;
+-----------+------+
| Host      | User |
+-----------+------+
| 127.0.0.1 | root |
| ::1       | root |
| localhost | root |
+-----------+------+
只有管理员一个用户
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

二、数据库用户的建立

MariaDB [(none)]> CREATE USER westos@localhost identified by 'westos';
建立一个用户只能在数据库所在的主机上使用(此用户只能本机登陆数据库),‘’引号引起来的为密码
  • 1
  • 2
MariaDB [(none)]> CREATE USER westo@'%'identified by 'westos';
建立一个可以远程登陆的用户(此用户可以通过网络登陆数据库),能否使用要看数据库远程登陆端口打开没
  • 1
  • 2

建立成功

MariaDB [(none)]> SELECT Host,User FROM mysql.user;
+-----------+--------+
| Host      | User   |
+-----------+--------+
| %         | westo  |
| 127.0.0.1 | root   |
| ::1       | root   |
| localhost | root   |
| localhost | westos |
+-----------+--------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

三、删除数据库用户

删除用户

MariaDB [(none)]> DROP USER westo@'%';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SELECT Host,User FROM mysql.user;
+-----------+--------+
| Host      | User   |
+-----------+--------+
| 127.0.0.1 | root   |
| ::1       | root   |
| localhost | root   |
| localhost | westos |
+-----------+--------+
MariaDB [(none)]> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
[root@server15 ~]# mysql -uwestos -pwestos
MariaDB [(none)]> quit
[root@server15 ~]# mysql -uwestos -pwestos -h172.25.138.15
ERROR 2003 (HY000): Can't connect to MySQL server on '172.25.138.15' (111)
[root@server15 ~]# mysql -ulee -pwestos -h172.25.138.15
ERROR 2003 (HY000): Can't connect to MySQL server on '172.25.138.15' (111)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

四、远程登录用户

我建立了一个远程登陆的用户lee

[root@server15 ~]# mysql -uroot -p
Enter password: 
MariaDB [(none)]> CREATE DATABASE westostest ;
MariaDB [(none)]> CREATE TABLE westostest.userlist (
    -> username varchar(10) not null,
    -> password varchar(30) not null
    -> );
MariaDB [(none)]> INSERT INTO westostest.userlist VALUES('lee','123'),('lee1','123');
MariaDB [(none)]> SELECT * FROM westostest.userlist;
+----------+----------+
| username | password |
+----------+----------+
| lee      | 123      |
| lee1     | 123      |
+----------+----------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

开启远程登陆接口

[root@server15 ~]# vim /etc/my.cnf.d/server.cnf 
  • 1

在这里插入图片描述
注释掉这个
远程登陆

[root@server15 ~]# systemctl restart mariadb.service 
[root@server15 ~]# mysql -ulee -pwestos -h172.25.138.15
MariaDB [(none)]> 
[root@server15 ~]# mysql -uwestos -pwestos -h172.25.138.15
ERROR 1045 (28000): Access denied for user 'westos'@'server15' (using password: YES)
  • 1
  • 2
  • 3
  • 4
  • 5

用westos用户登陆没有权限


五、没有权限

看不见表格

[root@server15 ~]# mysql -uwestos -pwestos
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

5.1授权查看

[root@server15 ~]# mysql -uroot -p
MariaDB [(none)]> GRANT SELECT ON westostest.* TO westos@localhost; westostest库里面所有表都可以查询.*
TO给westos@localhost这个用户
MariaDB [(none)]> SHOW GRANTS FOR westos@localhost;查看授权成功没
+---------------------------------------------------------------------------------------------------------------+
| Grants for westos@localhost                                                                                   |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'westos'@'localhost' IDENTIFIED BY PASSWORD '*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96' |
| GRANT SELECT ON `westostest`.* TO 'westos'@'localhost'                                                        |
+---------------------------------------------------------------------------------------------------------------+
GRANT SELECT ON `westostest`.* TO 'westos'@'localhost'
授权成功
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

授权能够查看但无法插入

[root@server15 ~]# mysql -uwestos -pwestos
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| westostest         |
+--------------------+
MariaDB [(none)]> SELECT * FROM westostest.userlist;
+----------+----------+
| username | password |
+----------+----------+
| lee      | 123      |
| lee1     | 123      |
+----------+----------+
2 rows in set (0.00 sec)
MariaDB [(none)]> INSERT INTO westostest.userlist VALUES('test','123');
ERROR 1142 (42000): INSERT command denied to user 'westos'@'localhost' for table 'userlist'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

5.2授权插入

[root@server15 ~]# mysql -uroot -p
MariaDB [(none)]> GRANT INSERT  ON westostest.* TO westos@localhost ;
MariaDB [(none)]> SHOW GRANTS FOR westos@localhost;
+---------------------------------------------------------------------------------------------------------------+
| Grants for westos@localhost                                                                                   |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'westos'@'localhost' IDENTIFIED BY PASSWORD '*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96' |
| GRANT SELECT, INSERT ON `westostest`.* TO 'westos'@'localhost'                                                |
+---------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
插入和查看权限都有了
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
[root@server15 ~]# mysql -uwestos -pwestos
MariaDB [(none)]> INSERT INTO westostest.userlist VALUES('test','123');
Query OK, 1 row affected (0.04 sec)
  • 1
  • 2
  • 3

5.3取消授权

[root@server15 ~]# mysql -uroot -p
MariaDB [(none)]> REVOKE INSERT ON westostest.* FROM westos@localhost;
MariaDB [(none)]> SHOW GRANTS FOR westos@localhost;
+---------------------------------------------------------------------------------------------------------------+
| Grants for westos@localhost                                                                                   |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'westos'@'localhost' IDENTIFIED BY PASSWORD '*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96' |
| GRANT SELECT ON `westostest`.* TO 'westos'@'localhost'                                                        |
+---------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
[root@server15 ~]# mysql -uwestos -pwestos
MariaDB [(none)]> INSERT INTO westostest.userlist VALUES('test1','123');
ERROR 1142 (42000): INSERT command denied to user 'westos'@'localhost' for table 'userlist'
  • 1
  • 2
  • 3

六、用户的所有权限

[root@server15 ~]# mysql -uroot -p
MariaDB [(none)]> SELECT * FROM mysql.user ;
  • 1
  • 2

在这里插入图片描述这个是所有权限比如:Select Insert Update …
在这里插入图片描述可以看到 root全是Y,所有权限都有
lee全是N没有任何权限

删掉用户

[root@server15 ~]# mysql -uroot -p
MariaDB [(none)]> DROP user westos@localhost;
  • 1
  • 2

END

系列文章目录

数据库的备份8


一、 数据库的备份

[root@server15 ~]# mysql -uroot -p
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westostest         |
+--------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
[root@server15 ~]# mysqldump -uroot -pwestos mysql
它便会把mysql的库的内容用SQL语句输出到我们的屏幕上
  • 1
  • 2

节选很长一段sql语句
在这里插入图片描述
所以把它重定向,便可以保存下来

[root@server15 ~]# mysqldump -uroot -pwestos mysql > /mnt/mysql.sql
  • 1

备份所有的库

[root@server15 ~]# mysqldump -uroot -pwestos --all-databases > /mnt/all.sql
  • 1

只要备份库的结构不备份库中的数据

[root@server15 ~]# mysqldump -uroot -pwestos --all-databases --no-data > /mnt/all.sql
  • 1
[root@server15 ~]# mysqldump -uroot -pwestos westostest > /mnt/westostest.sql
[root@server15 ~]# mysql -uroot -pwestos
MariaDB [(none)]> DROP DATABASE westostest;
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

使用备份的库时先得建立库,才能导入


二、数据库的还原

使用备份的库时先得建立库,才能导入

[root@server15 ~]# mysql -uroot -pwestos -e "CREATE DATABASE westostest"
[root@server15 ~]# mysql -uroot -pwestos westostest < /mnt/westostest.sql
  • 1
  • 2

数据库还原成功

[root@server15 ~]# mysql -uroot -pwestos 
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westostest         |
+--------------------+
MariaDB [(none)]> SELECT * FROM westostest.userlist;
+----------+----------+
| username | password |
+----------+----------+
| lee      | 123      |
| lee1     | 123      |
| test     | 123      |
+----------+----------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

END

系列文章目录

数据库的web界面管理器的部署9


数据库的web界面管理器的部署

可视化管理需要下载一个插件phpmyadmin
在这里插入图片描述
进入官网下载
我用的是3.4的版本,个人觉得好用

[root@foundation38 ~]# scp /var/run/media/kiosk/C6E6206CE6205EC5/phpMyAdmin-3.4.0-all-languages.tar.bz2 root@172.25.138.15:/mnt 
[root@server15 ~]# cd /mnt
[root@server15 mnt]# ls
all_nodata.sql  all.sql  mysql.sql  phpMyAdmin-3.4.0-all-languages.tar.bz2  westostest.sql
  • 1
  • 2
  • 3
  • 4

安装该插件

[root@server15 yum.repos.d]# yum install httpd php php-mysql.x86_64 -y
因为基于httpd发布,php默认不支持数据库,所以还得安装相应的插件让php支持数据库
[root@server15 yum.repos.d]# systemctl start firewalld.service 
[root@server15 yum.repos.d]# systemctl enable --now httpd
[root@server15 yum.repos.d]# systemctl restart httpd
[root@server15 yum.repos.d]# firewall-cmd --permanent --add-service=http
[root@server15 yum.repos.d]# firewall-cmd --reload
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在这里插入图片描述

[root@server15 mnt]# yum install bzip2 -y
[root@server15 mnt]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html/
[root@server15 mnt]# cd /var/www/html/
[root@server15 html]# ls
phpMyAdmin-3.4.0-all-languages
[root@server15 html]# mv phpMyAdmin-3.4.0-all-languages mysqladmin
改个名字要不然名字太长了,不好访问
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
[root@server15 html]# cd mysqladmin/
[root@server15 mysqladmin]# ls
  • 1
  • 2

在这里插入图片描述
软件的安装文档
在这里插入图片描述在这里插入图片描述

快速安装步骤

[root@server15 mysqladmin]# cp config.sample.inc.php config.sample.php
  • 1

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
END

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/786692
推荐阅读
相关标签
  

闽ICP备14008679号