您好,登錄后才能下訂單哦!
1、創建數據庫
MariaDB [(none)]> CRRATE DATABASE test1; #創建一個名為test1的數據庫 MariaDB [(none)]> CRRATE DATABASE IF NOT EXISTS test2; #創建一個名為test2的數據庫 MariaDB [(none)]> SHOW DATABASES; #顯示存在的數據庫
2、刪除數據庫
MariaDB [(none)]> DROP DATABASE test1; #刪除名為test1的數據庫 MariaDB [(none)]> DROP DATABASE IF EXISTS test1;
3、創建表
格式: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); #在數據庫test2中創建表teacher MariaDB [(none)]> USE test2; MariaDB [(test2)]> CREATE TABLE student(Name CHAR(20) NOT NULL,Age TINYINT UNSIGNED,Gender CHAR(1) NOT NULL); #另一種方式在數據庫test2中創建表student MariaDB [(test2)]> SHOW TABLES FROM test2; #查看數據庫test2中的表
4、查看表結構
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); #添加一個字段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、插入數據信息
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、修改更新數據信息
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、創建、刪除用戶
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'; #查看用戶的授權 MariaDB [(none)]> CREATE USER 'Lily'@'192.168.1.50' MariaDB [(none)]> CREATE USER 'Bob'@'%' #其中%為通配符,表示任意多的字符,下劃線_表示任意單個字符
10、授權
GRANT pri1,pri2,pri3,... ON dbname.tbname TO 'username'@'host' [IDENTIFIED BY 'password'];
REVOKE pri1,pri2,pri3,... ON dbname.tbname FROM 'username'@'host'; #取消權限
MariaDB [(none)]> GRANT ALL PRIVILEGES ON test2.* TO 'Lucy'@'%'; #授與用戶'Lucy'@'%'在test2庫所有表的全部的權限 MariaDB [(none)]> SHOW GRANTS FOR 'Lucy'@'%';
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。