日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

【Linux】数据库管理

發(fā)布時(shí)間:2025/5/22 linux 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Linux】数据库管理 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

數(shù)據(jù)庫(kù)(Database)是按照數(shù)據(jù)結(jié)構(gòu)來(lái)組織、存儲(chǔ)和管理數(shù)據(jù)的,是建立在計(jì)算機(jī)存儲(chǔ)設(shè)備上的倉(cāng)庫(kù)。?
簡(jiǎn)單來(lái)說(shuō)是本身可視為電子化的文件柜——存儲(chǔ)電子文件的處所,用戶(hù)可以對(duì)文件中的數(shù)據(jù)進(jìn)行新增、截取、更新、刪除等操作。?
一、安裝部署http://www.daiqiyang.com?
#系統(tǒng)默認(rèn)已經(jīng)安裝該數(shù)據(jù)庫(kù),如果沒(méi)有安裝,使用以下命令進(jìn)行安裝?
[root@mail ~]# yum install -y mariadb#啟動(dòng)數(shù)據(jù)庫(kù)服務(wù)?
[root@mail ~]# systemctl restart mariadb#初始化數(shù)據(jù)庫(kù)?
[root@mail ~]# mysql_secure_installation ????????????????????????????????????????這里第一次直接回車(chē):為數(shù)據(jù)庫(kù)的root設(shè)置密碼: ?后面做一些初始化設(shè)定,一般都選Y就可以了。#在防火墻添加永久允許策略?
[root@mail ~]# firewall-cmd --permanent --add-service=mysql#重新加載防火墻配置?
[root@mail ~]# firewall-cmd --reload二、登陸使用?
#數(shù)據(jù)庫(kù)系統(tǒng)登陸?
[root@mail ~]# mysql -uroot -predhat ????????????????????//注意這里的命令與參數(shù)之間沒(méi)有空格[root@mail ~]# mysql -uroot -p ???????????????????????????????//這樣登錄可以隱藏密碼 ?[root@mail ~]# mysql -u root -h localhost -p [DATABASE NAME]-u:連接mysql服務(wù)器的用戶(hù)名;?
-h:mysql服務(wù)器的ip地址或主機(jī)名;?
-p:連接mysql服務(wù)器的密碼;?
#查看系統(tǒng)有多少數(shù)據(jù)庫(kù)?
MariaDB [(none)]> show databases; ?????????????????????????????????????????//在數(shù)據(jù)庫(kù)中的命令都以;結(jié)尾#退出數(shù)據(jù)庫(kù)系統(tǒng)?
MariaDB [(none)]> quitMariaDB [(none)]> exit#創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)?
MariaDB [(none)]> create database luntan;#切換到某個(gè)數(shù)據(jù)庫(kù)下?
MariaDB [mysql]> use mysql;#查看數(shù)據(jù)庫(kù)的表?
MariaDB [mysql]> show tables;#查看數(shù)據(jù)表的表結(jié)構(gòu)?
MariaDB [mysql]> desc user;#查詢(xún)user表中的某些數(shù)據(jù)?
MariaDB [mysql]> select host,user,password from user;#創(chuàng)建一張表?
MariaDB [mysql]> create table person ( ???-> number int(11), ???-> name varchar(255), ???-> birthday date);#查詢(xún)創(chuàng)建好的表的表結(jié)構(gòu)?
MariaDB [mysql]> desc person;#插入幾條數(shù)據(jù)?
MariaDB [mysql]> insert into person (number,name,birthday) values (1,"haha",20191225);MariaDB [mysql]> insert into person (number,name,birthday) values (2,"xixi",20191226);MariaDB [mysql]> insert into person (number,name,birthday) values (3,"hehe",20191227);#查詢(xún)表的內(nèi)容?
MariaDB [mysql]> select * from person;#刪除表的內(nèi)容?
MariaDB [mysql]> delete from person where name="haha";MariaDB [mysql]> delete from person where number=3;#更新表中的數(shù)據(jù)?
MariaDB [mysql]> update person set name="haha" ?where name="xixi";MariaDB [mysql]> update person set number=1 where birthday=20191226;三、用戶(hù)的管理和訪問(wèn)權(quán)限的控制?
創(chuàng)建數(shù)據(jù)庫(kù)登陸用戶(hù)?
MariaDB [mysql]> create user xiaoming@localhost identified by 'redhat';MariaDB [mysql]> create user xiaohong@localhost identified by "redhat";MariaDB [mysql]> select host,user,password from user;查看當(dāng)前使用用戶(hù):?
MariaDB [(none)]> select user();查看當(dāng)前用戶(hù)的數(shù)據(jù)庫(kù):?
MariaDB [(none)]> select database();使用小明用戶(hù)登錄數(shù)據(jù)庫(kù):?
[root@localhost ~]# mysql -u xiaoming -p#查看可以訪問(wèn)的數(shù)據(jù)庫(kù)?
MariaDB [(none)]> show databases;#以root用戶(hù)登錄給xiaoming用戶(hù)一張表的權(quán)限?
MariaDB [(none)]> grant select,update,insert,delete on mysql.person to xiaoming@localhost;?退出數(shù)據(jù)庫(kù)系統(tǒng),并使用xiaoming用戶(hù)重新登陸?
[root@localhost ~]# mysql -u xiaoming -pMariaDB [(none)]> use mysql;#測(cè)試各種權(quán)限?
MariaDB [mysql]> select * from person;MariaDB [mysql]> insert person (number,name,birthday) value (3,"xiaoming",20181228);MariaDB [mysql]> update person set name="xixi" where number=1MariaDB [mysql]> delete from person where number=1;#使用root用戶(hù)登錄,改變xiaoming用戶(hù)的權(quán)限?
MariaDB [(none)]> revoke delete on mysql.person from xiaoming@localhost;#使用select語(yǔ)句進(jìn)行刪除表數(shù)據(jù),確認(rèn)權(quán)限已被禁用?
MariaDB [mysql]> delete from person where number=3 ;四、備份和還原?
備份整個(gè)數(shù)據(jù)庫(kù)的所有表?
[root@mail ~]# mysqldump -u root -p mysql > /mysql_backup_20160510.dump ????//做一個(gè)備份文件,位置可以選擇#使用root用戶(hù)登錄數(shù)據(jù)庫(kù),刪除person表?
MariaDB [mysql]> drop table person;#退出系統(tǒng),進(jìn)行還原操作?
[root@mail ~]# mysql -u root -p mysql < /mysql_backup_20160510.dump或者使用source命令讀入表信息。?
#登陸數(shù)據(jù)庫(kù)系統(tǒng)?
[root@mail ~]# mysql -u root -p#查看person表?
MariaDB [mysql]> select * from person;————————————————?

云專(zhuān)線為客戶(hù)網(wǎng)絡(luò)接入云提供高速直連通道,幫助您在不同的網(wǎng)絡(luò)環(huán)境中建立私人網(wǎng)絡(luò)通道,提高網(wǎng)絡(luò)拓?fù)涞撵`活性和跨網(wǎng)絡(luò)通信的質(zhì)量和安全性。
?

總結(jié)

以上是生活随笔為你收集整理的【Linux】数据库管理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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