CRRATE DATABASE test1; #創(chuàng)建一個(gè)名為test1的數(shù)據(jù)庫 MariaDB [(none)]>&nb..."/>
您好,登錄后才能下訂單哦!
1、創(chuàng)建數(shù)據(jù)庫
MariaDB [(none)]> CRRATE DATABASE test1; #創(chuàng)建一個(gè)名為test1的數(shù)據(jù)庫 MariaDB [(none)]> CRRATE DATABASE IF NOT EXISTS test2; #創(chuàng)建一個(gè)名為test2的數(shù)據(jù)庫 MariaDB [(none)]> SHOW DATABASES; #顯示存在的數(shù)據(jù)庫
2、刪除數(shù)據(jù)庫
MariaDB [(none)]> DROP DATABASE test1; #刪除名為test1的數(shù)據(jù)庫 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ù)庫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ù)庫test2中創(chuàng)建表student MariaDB [(test2)]> SHOW TABLES FROM test2; #查看數(shù)據(jù)庫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庫所有表的全部的權(quán)限 MariaDB [(none)]> SHOW GRANTS FOR 'Lucy'@'%';
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。