您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。