1 連接
mysql -u root -p 連接用戶
2 數(shù)據(jù)庫
create DATABASE testdb; 創(chuàng)建數(shù)據(jù)庫
drop database testdb; 刪除數(shù)據(jù)庫
show databases; 查看所有數(shù)據(jù)庫
show variables like ‘%max_connections%’; 查看數(shù)據(jù)庫最大連接數(shù)
use mysql;使用數(shù)據(jù)庫
select database(); 查看當(dāng)前數(shù)據(jù)庫
3??用戶
create user tester01 identified by '12345678';? 創(chuàng)建用戶
grant select,insert,update,delete,create on testdb to tester01;?
grant all privileges on testdb to admin;? 給用戶授權(quán)
flush privileges;?刷新
show grants for 'tester01';? 查看用戶授權(quán)信息
select distinct concat('user:',user,'@',host,';') as users from mysql.user; 查看數(shù)據(jù)庫所有用戶信息
delete from mysql.user where user='tester';? 刪除用戶
select user from mysql.user; 查看用戶
4 表
show tables; 查看數(shù)據(jù)庫表信息
創(chuàng)建表?PRIMARY KEY主鍵惧互,ENGINE 設(shè)置存儲引擎锦援,CHARSET 設(shè)置編碼
create table test01(
? ? -> id INT NOT NULL AUTO_INCREMENT,
? ? -> name VARCHAR(10) NOT NULL,
? ? -> age INT,
? ? -> date DATE,
? ? -> PRIMARY KEY (id)
? ? -> )ENGINE=InnoDB DEFAULT CHARSET=utf8;
表插入數(shù)據(jù)
insert into test01
? ? -> (name, age, date)
? ? -> values
? ? -> ('張三', 22, now());
查詢
select * from test01;
SELECT name, COUNT(*) FROM test01 GROUP BY name;? 統(tǒng)計
更新
update test01 set age=33 where name like '張%';