1、創(chuàng)建數(shù)據(jù)庫(kù)
創(chuàng)新互聯(lián)是一家專業(yè)提供梅河口企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、H5網(wǎng)站設(shè)計(jì)、小程序制作等業(yè)務(wù)。10年已為梅河口眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。
MariaDB [(none)]> CRRATE DATABASE test1; #創(chuàng)建一個(gè)名為test1的數(shù)據(jù)庫(kù) MariaDB [(none)]> CRRATE DATABASE IF NOT EXISTS test2; #創(chuàng)建一個(gè)名為test2的數(shù)據(jù)庫(kù) MariaDB [(none)]> SHOW DATABASES; #顯示存在的數(shù)據(jù)庫(kù)
2、刪除數(shù)據(jù)庫(kù)
MariaDB [(none)]> DROP DATABASE test1; #刪除名為test1的數(shù)據(jù)庫(kù) MariaDB [(none)]> DROP DATABASE IF EXISTS test1;
3、創(chuàng)建表
格式:CREAT TABLE tb_name(col1,col2,col3,...);
MariaDB [(none)]> CREATE TABLE test2.teacher(Name CHAR(20) NOT NULL,Age TINYINT UNSIGNED,Gender CHAR(1) NOT NULL); #在數(shù)據(jù)庫(kù)test2中創(chuàng)建表teacher MariaDB [(none)]> USE test2; MariaDB [(test2)]> CREATE TABLE student(Name CHAR(20) NOT NULL,Age TINYINT UNSIGNED,Gender CHAR(1) NOT NULL); #另一種方式在數(shù)據(jù)庫(kù)test2中創(chuàng)建表student MariaDB [(test2)]> SHOW TABLES FROM test2; #查看數(shù)據(jù)庫(kù)test2中的表
4、查看表結(jié)構(gòu)
MariaDB [(test2)]> DESCRIPTION student; MariaDB [(test2)]> DESC teacher; #DESCRIPTION可縮寫為DESC
5、刪除表
MariaDB [(test2)]> DROP TABLE teacher; MariaDB [(test2)]> DROP TABLE IF EXISTS teacher;
6、修改表
MariaDB [(test2)]> ALTER TABLE student ADD course VARCHAR(80); #添加一個(gè)字段course MariaDB [(test2)]> DESC student; MariaDB [(test2)]> ALTER TABLE student CHANGE course Course VARCHAR(80) AFTER Name; #修改course為Course,并放在Name后 MariaDB [(test2)]> DESC student;
7、插入數(shù)據(jù)信息
MariaDB [(test2)]> INSERT INTO student (Name,Gender) VALUE ('Tom','M'),('Jerry','F'); MariaDB [(test2)]> SELECT * FROM student; MariaDB [(test2)]> INSERT INTO student VALUE ('Jack','Math',16,'M');
8、修改更新數(shù)據(jù)信息
MariaDB [(test2)]> UPDATE student SET Course='Physics' WHERE Name='Tom'; #向名為Tom的行的Course字段插入Physics MariaDB [(test2)]> SELECT Name,Course FROM student WHERE Course='Physics'; #選擇student表中課程為物理的Name與Course MariaDB [(test2)]> DELETE FROM student WHERE Coures='Physics'; #刪除課程為物理的所有行
9、創(chuàng)建、刪除用戶
CREATE USER 'username'@'host' [IDENTIFIED BY 'password'];
DROP USER 'username'@'host';
MariaDB [(none)]> CREATE USER 'Lucy'@'localhost' INDENTIFIED BY '123456'; MariaDB [(none)]> SHOW GRANTS FOR 'Lucy'@'localhost'; #查看用戶的授權(quán) MariaDB [(none)]> CREATE USER 'Lily'@'192.168.1.50' MariaDB [(none)]> CREATE USER 'Bob'@'%' #其中%為通配符,表示任意多的字符,下劃線_表示任意單個(gè)字符
10、授權(quán)
GRANT pri1,pri2,pri3,... ON dbname.tbname TO 'username'@'host' [IDENTIFIED BY 'password'];
REVOKE pri1,pri2,pri3,... ON dbname.tbname FROM 'username'@'host'; #取消權(quán)限
MariaDB [(none)]> GRANT ALL PRIVILEGES ON test2.* TO 'Lucy'@'%'; #授與用戶'Lucy'@'%'在test2庫(kù)所有表的全部的權(quán)限 MariaDB [(none)]> SHOW GRANTS FOR 'Lucy'@'%';
本文題目:MariaDB的基礎(chǔ)操作
地址分享:http://muchs.cn/article4/gddoie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、微信公眾號(hào)、商城網(wǎng)站、網(wǎng)站營(yíng)銷、定制網(wǎng)站、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)