您好,登錄后才能下訂單哦!
數據庫的操作筆記:加油! 跳過授權登錄:1,關閉mysql;mysqld --skip-grant-tables 重新啟動客戶端不用密碼就可以登錄 遠程登錄數據庫: select user() 查看當前登錄用戶 建立本機賬號 create user 'admin'@'localhost' identified by '123456'; 建立遠程賬號 create user 'admin'@'%' identified by '123456'; 任意主機 create user 'admin'@'192.168.20.%' identified by '123456'; 固定網段主機 遠程登錄:mysql -h(IP) -uname -p 192.168.20.35 insert,delete,update,select 用戶授權: 級別1:對所有庫,下的所有表,下的所有字段 grant select on *.* to 'admin'@'%' identified by '123456'; 級別2:對庫db,下的所有表,下的所有字段 grant select on db.* to 'admin'@'%' identified by '123456'; 級別3;對表table,下的所有字段 grant select on db.table to 'admin'@'%' identified by '123456'; 級別4: 對表table 下的字段 grant select(id,name) on db.table to 'admin'@'%' identified by '123456'; flush privileges; 刷新 1 操作文件夾(數據庫): 增: create database database_name charset utf8; 查; show databases;查看所有的數據庫 show create database database_name 查看database_name 創建信息 改: alter database database_name charset gbk; 刪: drop database database_name; \c取消命令執行 進入文件夾操作文件(進入庫操作表)user database_name 2 操作文件(表): 增: create table table_name(id int,name char)engine=innodb default utf8; 查: show tables;(查看所有表) show create table_name;(查看創建表的信息) desc table_name;(查看表結構) 改: alter table table_name add age int;(增加字段) alter table table_name modify name char(12); 刪: drop table table_name; 3 操作文件的一行行內容(記錄): 增: insert into table_name values(1,'egon'),(2,'alex'); insert into table_name() values(); 查: select * from table_name; (查看所有) select name,id from table_name; 改: update table_name set name='SB' where id=4; 刪: delete from table_name;(整體干掉) delete from table_name where id =4;(刪除ID=4的) #推薦truncate刪除,速度快, delete from table_name; truncate table_name;(干掉所有,數據量大的時候刪除速度快) 自增ID (ID遞增在上一個的基礎上遞增) create table table_name(id int primary key auto_increment,name char); primary key =not null unique 復制表(所有內容):create table new_table_name select * from table_name; 復制表(不要內容):create table new_table_name select * from table_name where 1=2;(條件為假,內容不拷貝) 作業一: 建庫 create database db1 charset utf8; 建表插入字段 create table student(id int primary key auto_increment,name char,sex char,age int,lesson char,clsses char); create table teacher(id int primary key auto_increment,name char,sex char,age int,profess char,lesson char,clsses char); create table class(id int primary key auto_increment,name char); create table lesson(id int primary key auto_increment,name char,price int,period int); 插入數據 學生: insert into student(name,sex,age,lesson,clsses) values ('egon1','male',18,'pyhton','six'), ('egon2','male',18,'pyhton','six'), ('egon3','male',18,'pyhton','six'); 老師: insert into teacher(name,sex,age,profess,lesson,clsses) values ('egon1','male',18,'teachering','pyhton','six'), ('egon2','male',18,'teachering','pyhton','six'), ('egon3','male',18,'teachering','pyhton','six'); 班級: insert into class(name) values ('egon1'), ('egon2'), ('egon3'); 課程: insert into lesson(name,price,period)values ('pyhton0',18000,6), ('pyhton1',18000,6), ('pyhton2',18000,6); 作業二: 創建用戶lili,只是開放lili對學生表的查詢(select)與修改(update)權限 grant select,update on db1.student to 'lili'@'%' identified by '123456'; flush privileges; 創建用戶Jack,只開房Jack對老師表的查詢權限 grant select on db1.teacher to 'jack'@'%' identified by '123456'; flush privileges; 創建用戶Tom,只允許Tom查詢和修改課程表的名字和周期 grant select(name,period),update(name,period) on db1.lesson to 'tom'@'%' identified by '123456'; flush privileges;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。