安装教程
安装过程中出现报错的解决教程
Gpgcheck是GPG验证是否开启的选项,1是开启,0是不开启,一般情况可以关掉
连接到本机上的MYSQL
mysql -u root -p
退出
exit (回车)
CREATE DATABASE 数据库名;
show DATABASES;
use 数据库名;
drop database 数据库名;
CREATE TABLE table_name (column_name column_type);
例如:
CREATE TABLE istester (
id INT(10) NOT NULL UNIQUE PRIMARY KEY ,
uname VARCHAR(20) NOT NULL ,
sex VARCHAR(4) ,
birth YEAR,
department VARCHAR(20) ,
address VARCHAR(50) ,
idoxu VARCHAR(20)
);
CREATE TABLE targetTable LIKE sourceTable;
INSERT INTO targetTable SELECT * FROM sourceTable;
create table 新表 select * from 旧表 where 1=2
或者
create table 新表 like 旧表
create table新表 select * from 旧表
CREATE TABLE newadmin AS
(
SELECT username, password FROM admin
)
CREATE TABLE newadmin AS
(
SELECT id, username AS uname, password AS pass FROM admin
)
show tables;
DROP TABLE table_name ;
同时删除多个数据表
drop table table_name1,table_name2 ;
add/drop
ALTER table istester add column istester6 VARCHAR(100) NOT NULL;
ALTER table istester drop istester6
INSERT INTO table_name ( field1, field2,...fieldN )
VALUES
( value1, value2,...valueN );
delete from istester where id > 12;
UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]
SELECT column_name,column_name
FROM table_name
[WHERE Clause]
[LIMIT N][ OFFSET M]
SELECT field1, field2,...fieldN FROM table_name1, table_name2...
[WHERE condition1 [AND [OR]] condition2.....
ike 匹配/模糊匹配,会与 % 和 _ 结合使用。
‘%a’ //以a结尾的数据
‘a%’ //以a开头的数据
‘%a%’ //含有a的数据
‘a’ //三位且中间字母是a的
‘a’ //两位且结尾字母是a的
'a’ //两位且开头字母是a的
查询以 java 字段开头的信息。
SELECT * FROM position WHERE name LIKE 'java%';
默认升序排列,若降序需添加关键字desc
如:按id降序
select * from istester order by id desc;
默认升序:
select * from idoxu order by grade;
例如:查找istester表,id 包含 “1” 的数据 ,取id最大的三个
select * from istester where id like ‘%1%’ order by id desc limit 3 ;
例如:查找idoxu表,成绩在80 - 100区间的学生 ;
select * from idoxu where grade between 80 and 100;
例如:查找istester表,id 为 2,11,12 的数据 ;
select * from istester where id in (2,11,12) ;
注意这三者的区别
#左连接
SELECT * from idoxu6 a LEFT JOIN istester b on a.stu_id=b.id;
#内连接
SELECT * from idoxu6 a INNER JOIN istester b on a.stu_id=b.id;
#右连接
SELECT * from idoxu6 a RIGHT JOIN istester b on a.stu_id=b.id;
SELECT COUNT(ProductID) AS NumberOfProducts FROM Products;
例如:查询istester表,有性别类型数量(sex字段,去重)
select COUNT(DISTINCT sex) from istester;
SELECT MAX(Price) AS LargestPrice FROM Products;
SELECT AVG(Price) AS AveragePrice FROM Products;
SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;
隔一段时间还是要review下以下网页练习mysql的基础知识
练习-上
练习-中
练习-下