mariadb数据库管理

1、安装(配置好yum源进行下载 这里我们就不必多说了)

yum install mariadb-server -y(记得-server)
systemctl start maridb(下载后当然是要开启服务啊)

Linux-mariadb数据库管理Linux-mariadb数据库管理

2、安全初始化
1、默认情况下,数据库接口是打开的
为了安全需要关闭此接口
vim /etc/my.cnf    ##
关闭网络接口
 skip-networking=1

Linux-mariadb数据库管理Linux-mariadb数据库管理
systemtl restart mariadb

Linux-mariadb数据库管理

2、数据库起始状态信是不安全的,需要做设置密码

如下图我们mysql可以直接登录

Linux-mariadb数据库管理

[[email protected] logs]# mysql_secure_installation(所以这里我们需要进行初始的设置 设置好密码一直Y)

Linux-mariadb数据库管理


3
、密码的管理

改密码(知道自己原来的密码)
[[email protected] logs]# mysqladmin -uroot -pannie password chenjiebin(这里把原来的密码annie改为了chenjiebin 登录可以看到原来的密码登录不上了 现在的可以 证明密码更改成功)

Linux-mariadb数据库管理

当超级用户忘记密码

[[email protected] logs]# systemctl stop mariadb.service (先关闭数据库服务)
[[email protected] logs]# mysqld_safe --skip-grant-tables &(跳过登录的权限检测)
[1] 5733
[[email protected] logs]# mysql(跳过安全检测之后就可以不需要用户密码直接登录了)
MariaDB [(none)]> update mysql.user set Password=password('riven') whereUser='root'
    -> ;(这里就把root用户的密码更改成为了riven)
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

Linux-mariadb数据库管理

尝试登录 发现密码修改成功

Linux-mariadb数据库管理


[[email protected] logs]# ps aux | grep mysql(查看MySQL的所有进程)

[email protected] logs]# systemctl start mariadb
[[email protected] mysql]# mysql -uroot -priven
4
、数据库的管理
MariaDB [(none)]> SHOW DATABASES;            
列出库

Linux-mariadb数据库管理

MariaDB [(none)]> CREATE DATABASE LALALA;    建立名字为LALALA的库
MariaDB [(none)]> USE LALALA          
进入LALALA库

Linux-mariadb数据库管理

MariaDB [WESTOS]> CREATE TABLE hahaha(
    -> username varchar(50) notnull,

    -> username varchar(50) notnull
    -> );                                     ##
建立名为hahaha的表的内容
MariaDB [WESTOS]> DESC hahaha                ##
查看表的结构

Linux-mariadb数据库管理

MariaDB [WESTOS]> INSERT INTO hahaha VALUES ('annie','123'); ##
插入数据到hahaha表中
Query OK, 1 row affected (0.34 sec)

Linux-mariadb数据库管理

MariaDB [WESTOS]> SELECT username from hahaha   ##查询指定字段在hahaha表中
 Linux-mariadb数据库管理


更改表格信息

MariaDB [WESTOS]> UPDATE linux SET password=password('234')  where username='annie'; ##更改表内容

Linux-mariadb数据库管理

不加用户的话是直接全部更更改 如下图所示

Linux-mariadb数据库管理


MariaDB [WESTOS]> ALTER TABLE hahaha ADD class varchar(20);    给文件里面添加相应内容                     

Linux-mariadb数据库管理

MariaDB [WESTOS]> ALTER TABLE hahaha DROP class;                   ##丢弃hahaha表格里面的class内容

Linux-mariadb数据库管理

MariaDB [WESTOS]> ALTER TABLE linux ADD age varchar(20) AFTER password;               ##在某一个指定的地方加入项目(这里我们选择在username后面加入了age)

Linux-mariadb数据库管理


MariaDB [WESTOS]> ALTER TABLE hahaha RENAME HAHAHA;                   ##更改整个表格的名字

Linux-mariadb数据库管理

刷新命令
MariaDB [(none)]> flush privileges;


删除
MariaDB [WESTOS]> DELETE FROM HAHAHA where username='annie';                        ##
删除表中的某一行

Linux-mariadb数据库管理

MariaDB [WESTOS]> DROP TABLE redhat;                                                 ##删除某一个表

Linux-mariadb数据库管理

MariaDB [WESTOS]> DROP DATABASE WESTOS;                                              ##删除某一个库

MariaDB [(none)]> SHOW DATABASES;                                                     ##查询,该库是否还存在

Linux-mariadb数据库管理



数据所在的目录路径  /var/lib/mysql,在这个路径创建相应的东西,在mysql中也会有相应的展现。
用户授权

1、建立这个用户
MariaDB [(none)]> DROP USER [email protected]  
@'%'的区别在于,'%'可以进行远程登陆,更加不安全。
MariaDB [(none)]> CREATE USER [email protected]'localhost' identified by'annie';  #
建立名为chenjiebin的用户,且登陆密码为annie
MariaDB [(none)]> GRANT SELECT,INSERT on annie.* TO [email protected];    #
chenjiebin用户SELECT,INSERT的权限

MariaDB [(none)]> SHOW GRANTS FOR [email protected];                       #显示系统给与chenjiebin用户的权限

Linux-mariadb数据库管理
用我们创建的这个用户登录一下 看看是否可以登录成功 成功的话表示用户创建完成

Linux-mariadb数据库管理


MariaDB [(none)]> REVOKE INSERT on annie.* FROM [email protected];        #移除chenjiebin的权限
MariaDB [(none)]> DROP USER [email protected];                             #
移除chenjiebin用户

Linux-mariadb数据库管理
Linux-mariadb数据库管理


5、数据库的备份
[[email protected] mysql]# mysqldump -uroot -pwestos westos > /mnt/westos.sql    ##
备份westos库中的内容

Linux-mariadb数据库管理
[[email protected] mysql]# mysqldump -uroot -pwestos westos --all-database >/mnt/westos.sql ##
备份库中的所有内容及其架构
[[email protected] mysql]# mysqldump -uroot -pwestos westos --all-database --no-data> /mnt/westos.sql ##
备份库中的架构

做实验前我们把WESTOS数据库删除

Linux-mariadb数据库管理

恢复方式1
[[email protected] mysql]# mysql -uroot -pwestos -e "CREATE DATABASE westos;"
[[email protected] mysql]# mysql -uroot -pwestos westos < /mnt/westos.sql 

Linux-mariadb数据库管理

恢复方式2(推荐使用这个方法)
vim /mnt/westos.sql
 21 CREATE DATABASE westos;
 22 USE westos;

Linux-mariadb数据库管理
[[email protected] mysql]# mysql -uroot -pwestos < /mnt/westos.sql
(进入数据库中查看发现恢复WESTOS数据库成功)
Linux-mariadb数据库管理

6、安装phpmyadmin数据库图形管理

1、下载phpMyAdmin-3.4.0-all-languages.tar.bz2(下载好放到/var/www/html/下进行解压)
2
yum install php -y

Linux-mariadb数据库管理
3
yum install php-mysql.x86_64 -y

Linux-mariadb数据库管理
4
systemctl restart httpd.service
5
cp phpMyAdmin-3.4.0-all-languages.tar.bz2/var/www/html/
6
cd /var/www/html/

Linux-mariadb数据库管理
7
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
8
mv phpMyAdmin-3.4.0-all-languages mysqlphp

Linux-mariadb数据库管理
9
cd mysqlphp/
10
less README(让我们去看Documentation.txt这个文件 那我们就去呗)

Linux-mariadb数据库管理
11
less Documentation.txt

Linux-mariadb数据库管理
Linux-mariadb数据库管理

12cp config.sample.inc.php config.inc.php

Linux-mariadb数据库管理

13vim config.inc.php

14 17 $cfg['blowfish_secret'] = '17c1ec07d65003'; 

Linux-mariadb数据库管理
测试:
http://172.25.254.100/mysqlphp

Linux-mariadb数据库管理
一定要开启httpd服务,火墙关闭
有错误的话,安全上下文,
2002selinux
forbidden
selinux的问题,通常是安全上下文的问题,不要移动,要拷贝

1045是密码错误


登陆进去后呢

Linux-mariadb数据库管理

我们在LALALA表中新添加'hahaha 233'

Linux-mariadb数据库管理

我们可以打开数据库进行查看  发现LALALA表格中确实添加了我们刚才执行的内容

Linux-mariadb数据库管理


7.运用httpd mysql 创建自己的论坛

1.首先从网上下载论坛模板并进行解压 如下图所示

Linux-mariadb数据库管理

2.浏览器浏览172.25.254.100/upload进行安装

Linux-mariadb数据库管理

3.安装时涉及到一些权限的问题 我们赋予777的权限来进行安装

Linux-mariadb数据库管理

Linux-mariadb数据库管理

4.设置运行环境

Linux-mariadb数据库管理

5.设置自己的信息

Linux-mariadb数据库管理

6.等待安装啦

Linux-mariadb数据库管理

7.登录自己的论坛0.0

Linux-mariadb数据库管理

-.-

Linux-mariadb数据库管理

这个好像是我的个人信息哦0.0

Linux-mariadb数据库管理


到此为止    休息休息0.0

相关文章: