mysql賬戶操作:
進入MySQL:sudo MySQL -u root -p 密碼

創(chuàng)建MySQL賬戶:create user '賬號名稱' @ ‘%’ identified by ‘賬號密碼’; #注意賬號名稱不可以重復,不然會報錯,名稱可以自己定義,創(chuàng)建MySQL賬戶必須進入MySQL
? ? ? ? 給創(chuàng)建的賬號所有權限:grant all on *.* to '需要賦予權限的賬號名稱' @ ‘%’;
然后直接刷新就行了:flush privileges; 之后進入便可以用賬戶登錄:

我創(chuàng)建了一個叫‘laowang’的賬戶?
MySQL庫的操作:
? ? ? ? 查看所有庫 : select database();
? ? ? ? 打開多有數(shù)據(jù)庫 :show databases;
? ? ? ? 創(chuàng)建數(shù)據(jù)庫 :create databa 數(shù)據(jù)庫名稱;
? ? ? ? 刪除數(shù)據(jù)庫 :drop database 需要刪除的數(shù)據(jù)庫名稱;
? ? ? ? 使用數(shù)據(jù)庫 : use? 需要進入的數(shù)據(jù)庫名稱;
mysql表及數(shù)據(jù)的操作:
? ? ? ? 創(chuàng)建表:create table? 表的名字(id int , name varchar(字段自己定義) , class varchar(10));#這里我創(chuàng)建了一個t1的表

查看表 :show tables;
查看表結構 :show create table 表名
往表里插入單條數(shù)據(jù):insert into 需要插入數(shù)據(jù)的表(id,name)values(1,'xiaoli');

插入多條數(shù)據(jù) :insert into 需要插入數(shù)據(jù)的表(id,name)values(1,'xiaoli'),(2 , 'xiaohon'),(3 , 'xiaoming');

#注意表中的class我沒有加數(shù)據(jù)所有會顯示null?
查詢表里的所有數(shù)據(jù) :?select * from 表名;
只查詢name的數(shù)據(jù) :? select name from 表名;

?有條件的查詢 :select id from 表名 where id<x; 或者?select *?from 表名 where id<x;#區(qū)別看下圖:

? 修改數(shù)據(jù):update 表名 set name='要修改的字段' where id=x;

對照上面的圖 我將id1修改成‘xiaohuang’?? # 注意如果不加where id=x就會將所有數(shù)據(jù)修改

?刪除數(shù)據(jù) :?delete from 表名 where id=1;#刪除的字段
刪除表:delete from 表名;