日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

MARIADB数据库服务器

發(fā)布時(shí)間:2023/12/20 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MARIADB数据库服务器 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

MARIADB數(shù)據(jù)庫服務(wù)器

? MariaDB 是一個(gè)采用 Maria 存儲(chǔ)引擎的MySQL分支版本,是由原來 MySQL 的作者Michael Widenius創(chuàng)辦的公司所開發(fā)的免費(fèi)開源的數(shù)據(jù)庫服務(wù)器

關(guān)系型數(shù)據(jù)庫:數(shù)據(jù)庫中數(shù)據(jù)與數(shù)據(jù)有關(guān)系,表與表有關(guān)系(例如:學(xué)生信息表)

非關(guān)系型數(shù)據(jù)庫:內(nèi)存數(shù)據(jù)庫、文檔數(shù)據(jù)庫、鍵值對(duì)數(shù)據(jù)庫(key=value)、時(shí)序數(shù)據(jù)庫等

一、安裝部署

1.系統(tǒng)默認(rèn)已經(jīng)安裝該數(shù)據(jù)庫,如果沒有安裝,使用以下命令進(jìn)行安裝

[root@mail ~]# yum install -y mariadb*

2.啟動(dòng)數(shù)據(jù)庫服務(wù)

[root@mail ~]# systemctl start mariadb

3.初始化數(shù)據(jù)庫

[root@mail ~]# mysql_secure_installation


注:初始化之后的密碼不是本機(jī)root的密碼,而是數(shù)據(jù)庫的密碼,直接回車進(jìn)入下一步輸入兩次設(shè)置密碼,后面其他所有的選項(xiàng)都選Y

4.在防火墻添加永久允許策略

[root@mail ~]# firewall-cmd --permanent --add-service=mysql

5.重新加載防火墻配置

[root@mail ~]# firewall-cmd --reload

二、登陸使用

1.數(shù)據(jù)庫系統(tǒng)登陸

[root@mail ~]# mysql -uroot -predhat #帶密碼登錄 [root@mail ~]# mysql -uroot -p [root@mail ~]# mysql -u root -h localhost -p [DATABASE NAME]

? 查看系統(tǒng)有多少個(gè)數(shù)據(jù)庫

MariaDB [(none)]> show databases; #[none]代表沒使用數(shù)據(jù)庫

2.退出數(shù)據(jù)庫系統(tǒng)

MariaDB [(none)]> quit MariaDB [(none)]> exit

3.創(chuàng)建一個(gè)數(shù)據(jù)庫

MariaDB [mysql]> create database luntan;

5.切換到某個(gè)數(shù)據(jù)庫下

MariaDB [mysql]> use mysql; #使用mysql這個(gè)數(shù)據(jù)庫

? 查看數(shù)據(jù)庫的表

MariaDB [mysql]> show tables;

? 查看數(shù)據(jù)表的表結(jié)構(gòu)

MariaDB [mysql]> desc user;

? 查詢user表中的某些數(shù)據(jù)

MariaDB [mysql]> select host,user from user;

? 創(chuàng)建一張表

MariaDB [mysql]> create table person (NUMBER INT(11), #字段名稱,數(shù)據(jù)類型(長度)NAME VARCHAR(255),BIRTHDAY DATE ); #日期類型不指定長度

? 查詢創(chuàng)建好的表的表結(jié)構(gòu)

MariaDB [mysql]> desc person;

增刪改查操作

? 插入幾條數(shù)據(jù)

MariaDB [mysql]> insert into person (number,name,birthday) values (1,'haha',20160509); #()里也可以不填字段,但后面填數(shù)據(jù)必須跟建表字段的順序一致 MariaDB [mysql]> insert into person (number,name,birthday) values (2,'heihei',20160609); MariaDB [mysql]> insert into person (number,name,birthday) values (3,'maomao',20160709);

? 查詢表的內(nèi)容

MariaDB [mysql]> SELECT * FROM person; #*代表所選數(shù)據(jù)中所有的內(nèi)容

? 刪除表的內(nèi)容

MariaDB [mysql]> delete from person where name="maomao"; MariaDB [mysql]> delete from person where number=1;

? 更新(修改)表中的數(shù)據(jù)

MariaDB [mysql]> update person set name="xixi" where name="heihei"; MariaDB [mysql]> update person set name="haha" where number=2;

三、用戶的管理和訪問權(quán)限的控制

mysql -u(用戶名) -p(密碼) #用某個(gè)用戶登錄時(shí)需退出數(shù)據(jù)庫

1.創(chuàng)建數(shù)據(jù)庫登陸用戶

MariaDB [mysql]> create user maomao@localhost identified by 'redhat'; MariaDB [mysql]> create user xixi@localhost identified by 'xixi';

identified by后面跟的是創(chuàng)建用戶的密碼

查看結(jié)果

MariaDB [mysql]> select host,user from user where user="maomao";

2.退出數(shù)據(jù)庫重新使用maomao用戶登錄數(shù)據(jù)庫

[root@mail ~]# mysql -u maomao -p

? 查看可以訪問的數(shù)據(jù)庫

MariaDB [(none)]> show databases;

? 給maomao用戶一張表的權(quán)限

MariaDB [mysql]> grant select,update,insert,delete on mysql.person to maomao@localhost; #mysql.person mysql中的person表

3.退出數(shù)據(jù)庫系統(tǒng),并使用maomao用戶重新登陸
測(cè)試查詢的權(quán)限

MariaDB [mysql]> select * from person;

? 測(cè)試插入的權(quán)限

MariaDB [mysql]> insert into person (number,NAME,BIRTHDAY) value (1,"hehe",20161010);

? 測(cè)試更新數(shù)據(jù)的權(quán)限

MariaDB [mysql]> update person set name="heihei" where number=2;

? 測(cè)試刪除數(shù)據(jù)的權(quán)限

MariaDB [mysql]> delete from person where number=1;

4.使用root用戶登錄,改變maomao用戶的權(quán)限

MariaDB [mysql]> revoke select on mysql.person from maomao@localhost;

? 使用select語句進(jìn)行查詢表,確認(rèn)權(quán)限已被禁用

MariaDB [mysql]> select * from person;

四、備份和還原

1.備份:使用root用戶登錄數(shù)據(jù)庫,用mysqldump命令導(dǎo)出數(shù)據(jù)庫

[root@mail ~]# mysqldump -u root -p mysql > /tmp/mysql_backup_20160510.dump #p后面為導(dǎo)出的數(shù)據(jù)庫名稱,/后為導(dǎo)出目錄

? 查詢person表

MariaDB [mysql]> select * from person;

? 刪除表

MariaDB [mysql]> drop table person;

2.退出系統(tǒng),進(jìn)行還原操作

[root@mail ~]# mysql -u root -p mysql < /tmp/mysql_backup_20160510.dump #p后面為要還原的數(shù)據(jù)庫名稱,/后為原先備份的數(shù)據(jù)庫儲(chǔ)存的目錄

? 登陸數(shù)據(jù)庫系統(tǒng),使用root用戶

[root@mail ~]# mysql -u root -p

? 查看person表

MariaDB [mysql]> select * from person;

? 可看到導(dǎo)出后數(shù)據(jù)庫,和備份前的數(shù)據(jù)庫的數(shù)據(jù)一樣,不受前面刪除的影響

總結(jié)

以上是生活随笔為你收集整理的MARIADB数据库服务器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。