创建数据库test:
CREATE DATABASE test;
切换到数据库test:
USE test;
创建数据表test_table,包含字段user_id,tel,并将tel设置为不重复的:
CREATE TABLE test_table (
user_id CHAR(100) NOT NULL,
tel CHAR(11) NOT NULL,
PRIMARY KEY (tel)
);
显示数据表的字段(列):
SHOW COLUMNS FROM test_table;
插入数据:
INSERT INTO test_table (user_id,tel) VALUES("测试0","0");
INSERT INTO test_table VALUES("测试1","1"),("测试2","2");
INSERT INTO test_table SELECT * FROM test_table;//选择test_table的所有数据项插入test_table
从test_table表中删除user_id等于'测试0'的数据:
DELETE FROM test_table WHERE user_id='测试0';
显示用户的权限:
SHOW GRANTS FOR test@localhost;
创建用户test并设置密码为123:
CREATE USER test@localhost IDENTIFIED BY '123';
授予用户test在localhost端口对test数据库test_table表所有权限:(有待考察)
GRANT ALL ON test.test_table TO test@localhost;
授予用户test在localhost端口对test数据库的所有权限:(先切换到test数据库)
USE test;
GRANT ALL ON test TO 'test'@'localhost';
网友评论