MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

MariaDB虽然被视为MySQL数据库的替代品,但它在扩展功能、存储引擎以及一些新的功能改进方面都强过MySQL。而且从MySQL迁移到MariaDB也是非常简单的



一.安装

[[email protected] html]# yum install mariadb-server.x86_64 -y
lamp————mariaDB

[[email protected] html]# systemctl start mariadb






二.安全初始化


1.  默认情况下,数据库的网络接口是打开的 为了安全需要关闭此接口

*)修改配置文件关闭网络接口

    [[email protected] html]# vim /etc/my.cnf
lamp————mariaDB

*)重启服务 更新配置

[[email protected] html]# systemctl restart mariadb.service

*)测试
lamp————mariaDB


2.数据库起始状态设定信息是不安全的 给其设定密码

*)给root设定密码

     [[email protected] html]# mysql_secure_installation
lamp————mariaDB


*)[[email protected] html]# mysql -uroot -p

lamp————mariaDB








三.数据库的密码设置


1.修改超级用户密码

[[email protected] html]# mysqladmin -uroot -p19970214 password zhanglu  ##-u用户名 -p原密码 password 新密码

lamp————mariaDB




2.当超级用户密码忘记时

*)systemctl stop mariadb.service ##关闭服务

*)mysqld_safe --skip-grant-tables & ##跳过初始化设定

lamp————mariaDB


*)[[email protected] html]# mysql  ##进入mysql

     MariaDB [(none)]> select * from mysql.user;   ##查看mysql.user文件
 lamp————mariaDB
     MariaDB [(none)]> update mysql.user set Password=password('19970214') where User='root';   ##修改 mysql.user中的root 的password 用password密文的方式
     MariaDB [(none)]> quit
     Bye


*)过滤 mysql的进程
lamp————mariaDB


*)kill -9 mysql的所有进程id
lamp————mariaDB


*)重新开启服务 完成密码重制
lamp————mariaDB









四.数据库的管理


*)建立

1.SHOW DATABASES;##查看库信息

lamp————mariaDB


2.CREATE DATABASE zl;   ##建立数据库

lamp————mariaDB


3.USE zl;  ##进入某个库

lamp————mariaDB


4.CREATE TABLE  linux (
    -> username varchar(50) not null,     ##创建字段名字为username 不超过50个字节 不能为空
    -> password varchar(50) not null
    -> );    ##创建一个表

lamp————mariaDB


5. DESC linux;   ##查看表的结构

lamp————mariaDB


6.INSERT INTO linux VALUES ('zhanglu','123');  ##插入(在表里添加数据)
lamp————mariaDB

7.SELECT  *  from linux;                  ##查看所以字段在表中

lamp————mariaDB


8.SELECT username,password  from linux;   ##查看指定字段在表中

lamp————mariaDB



*)更改

1.UPDATE linux SET password=password('zl') where username='ZHANGLU';  ##对密码进行>更新

lamp————mariaDB


2.ALTER TABLE linux ADD class varchar(20);  ##表中添加字段

lamp————mariaDB


3. ALTER TABLE linux DROP class;   ##删除某个字段

lamp————mariaDB


4.ALTER TABLE linux ADD age varchar(20) AFTER  password;  ##在指定位置添加字段

lamp————mariaDB


5.ALTER TABLE linux RENAME redhat;  ##更改表名字

lamp————mariaDB





*)删除

1.DELETE FROM redhat where username='ZHANGLU';  ##删除数据

lamp————mariaDB


2.DROP TABLE redhat;   ##删除表

lamp————mariaDB


3.DROP DATABASE zl;   ##删除库

lamp————mariaDB






五.用户授权

*)创建用户
CREATE USER [email protected] identified by 'westos';
CREATE USER [email protected]'%' identified by 'redhat'; ##创建可远程登陆的用户及密码
*)用户授权
GRANT INSERT,UPDATE,DELETE,SELECT on mariadb.* to [email protected];  ##INSERT插入,UPDATE更新,DELETE删除,SELECT查看
GRANT SELECT on mariadb.* [email protected]'%';
*)重载授权表
FLUSH PRIVILEGES;
*)查看用户授权
SHOW GRANTS FOR [email protected];
*)撤销用户权限
REVOKE DELETE,UPDATE,INSERT on mariadb.* from [email protected];
*)删除用户
DROP USER [email protected];



1.CREATE USER  [email protected]'localhost' identified by 'zl';             ##创建用户(本地用户和密码)

lamp————mariaDB


2.GRANT SELECT,INSERT on zl.* TO [email protected];        ##用户授权SELECT,INSERT权限
lamp————mariaDB


3.SHOW GRANTS FOR [email protected];                                  ##查看用户授权

lamp————mariaDB


4.REVOKE INSERT ON zl.*  FROM [email protected]      ##撤销用户权限

lamp————mariaDB


5.DROP USER [email protected]##删除用户

lamp————mariaDB






六.备份与恢复

1.备份

mysqldump -uroot -predhat zl > zl.dump   ##备份某个数据库所有内容

mysqldump -uroot -predhat --all-databases > backup.dump  ##备份所有数据库

mysqldump -uroot -predhat --no-data zl > zl.dump  ##备份某个数据库的框架  不要内容

lamp————mariaDB


2.恢复

*)方法一

[[email protected] html]# mysql -uroot -p19970214 -e "CREATE DATABASE zl;"

lamp————mariaDB

[[email protected] html]# mysql -uroot -p19970214 zl < ./zl.dump
lamp————mariaDB


*)方法二

[[email protected] html]# vim ./zl.dump

lamp————mariaDB


[[email protected] html]# mysql -uroot -p19970214 zl < ./zl.dump

lamp————mariaDB








七.安装phpmyadmin数据库图形管理

phpMyAdmin 是一个以PHP为基础,以Web-Base方式架构在网站主机上的MySQL的数据库管理工具,让管理者可用Web接口管理MySQL数据库。借由此Web接口可以成为一个简易方式输入繁杂SQL语法的较佳途径,尤其要处理大量资料的汇入及汇出更为方便。其中一个更大的优势在于由于phpMyAdmin跟其他PHP程式一样在网页服务器上执行,但是您可以在任何地方使用这些程式产生的HTML页面,也就是于远端管理MySQL数据库,方便的建立、修改、删除数据库及资料表。也可借由phpMyAdmin建立常用的php语法,方便编写网页时所需要的sql语法正确性。


1.下载phpMyAdmin-3.4.0-all-languages 安装包

lamp————mariaDB

2.安装PHP MySQL 连接数据库

[[email protected] ~]# yum install php php-mysql.x86_64  -y

lamp————mariaDB


3.重启httpd

[[email protected] ~]# systemctl restart  httpd.service


4.将安装包复制到/var/www/html/默认发布目录下 以便测试

*)[[email protected] ~]# cd /var/www/html/

*)[[email protected] html]# cp /root/Desktop/phpMyAdmin-3.4.0-all-languages.tar.bz2 ./
     [[email protected] html]# ls
     admin       index.php                               test       virtual
     index.html  phpMyAdmin-3.4.0-all-languages.tar.bz2  test.html


5.解压安装包

*)[[email protected] html]#  tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
*)[[email protected] html]# ls
     admin       phpMyAdmin-3.4.0-all-languages          test.html
     index.html  phpMyAdmin-3.4.0-all-languages.tar.bz2  virtual
     index.php   test


6.重命名数据库管理软件目录 方便管理

lamp————mariaDB

lamp————mariaDB


7.查看参考资料Documentation.txt 内容 对数据库管理软件进行配置

*)[[email protected] mysqladmin]# vim Documentation.txt
lamp————mariaDB

*)[[email protected] mysqladmin]# cp config.sample.inc.php config.inc.php

*)[[email protected] mysqladmin]# vim config.inc.php

lamp————mariaDB


8.测试

lamp————mariaDB

lamp————mariaDB























相关文章:

  • 2021-07-12
  • 2022-12-23
  • 2021-08-19
  • 2021-08-17
  • 2021-12-05
  • 2021-11-01
  • 2021-10-23
猜你喜欢
  • 2022-01-01
  • 2021-09-09
  • 2022-12-23
  • 2021-09-12
  • 2021-05-30
  • 2022-12-23
  • 2021-10-31
相关资源
相似解决方案