时间:2021-07-01 10:21:17 帮助过:16人阅读
1、查看一个字段在哪些表中:
use information_schema;
select table_name form columns where column_name=‘xxx‘
2、查看建表语句
show create table tablename
3、修改列的数据类型
alert table 表名 modify column 列名 新的列的类型
alert table example modify column col1 varchar(10)
只修改列名,或者同时修改列明和列的数据类型
alert table 表名 change column 旧列名 新列名 新的列类型
alert table example change column sname stuname varchar(10)
4、This version of MySQL doesn‘t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery‘的意思是,
这版本的 MySQL 不支持使用 LIMIT 子句的 IN/ALL/ANY/SOME 子查询,即是支持非 IN/ALL/ANY/SOME 子查询的 LIMIT 子查询。
也就是说,这样的语句是不能正确执行的。
select * from table where id in (select id from table limit 10)
但是,只要你再来一层就行。。如:
select * from table where id in (select t.id from (select * from table limit 10)as t)
5、三张表join
select xxx from (( A left join B on A.id = B.id)
left join C on A.id = C.id
where B.id is not null
select * from A inner join B on A.id = A.id inner join C on B.id = C.id
6、增加一个字段
alert table tablename add column fieldname dataType
7、复制表
create table table2 select * from table1
对表重新命名
alert table table1 rename as table2
修改列的类型
alert table table1 modify id int unsigned
创建索引
create (unique唯一索引)index ide_id on table1 (id)
删除索引
drop index inx_id on table1
8、linux进入MySQL方式:
1) 进入MySQL安装目录下的bin文件夹下,执行./mysql -uroot -p
2)export PATH=/usr/local/mysql/bin:$PATH 这种方法在终端关闭
的时候会失效。
3)vim /ect/profile
在最后添加: export PATH="/usr/local/mysql/bin:$PATH"保存,退出
source /ect/profile 不报错则成功
1、查看数据库的连接数:
SELECT summary_id,COUNT(*) AS COUNT FROM pe_project_summary_basic GROUP BY summary_id HAVING COUNT>1;
摘录于MySQL官网 修改表/数据库字符编码 alter database mydb character set utf-8; alter table conf_dictitem convert to character set utf8 4、外键示例 CREATE TABLE person ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR(60) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE shirt ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, style ENUM(‘t-shirt‘, ‘polo‘, ‘dress‘) NOT NULL, color ENUM(‘red‘, ‘blue‘, ‘orange‘, ‘white‘, ‘black‘) NOT NULL, owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id), PRIMARY KEY (id) ); INSERT INTO person VALUES (NULL, ‘Antonio Paz‘); SELECT @last := LAST_INSERT_ID(); INSERT INTO shirt VALUES (NULL, ‘polo‘, ‘blue‘, @last), (NULL, ‘dress‘, ‘white‘, @last), (NULL, ‘t-shirt‘, ‘blue‘, @last); INSERT INTO person VALUES (NULL, ‘Lilliana Angelovska‘); SELECT @last := LAST_INSERT_ID(); INSERT INTO shirt VALUES (NULL, ‘dress‘, ‘orange‘, @last), (NULL, ‘polo‘, ‘red‘, @last), (NULL, ‘dress‘, ‘blue‘, @last), (NULL, ‘t-shirt‘, ‘white‘, @last); SELECT s.* FROM person p INNER JOIN shirt s ON s.owner = p.id WHERE p.name LIKE ‘Lilliana%‘ AND s.color <> ‘white‘; 3、SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop; SELECT * FROM shop WHERE price=@min_price OR price=@max_price; 1、 匹配语句 SELECT * FROM pet WHERE name REGEXP ‘w‘; 包含w字符, ^w以w开头的字符, w$以w结尾的字符, ‘^.....$‘ 长度为五个字符(如果是中文的话,一个中文为3个...,即一个中文占三个字符), ‘^.{6}$‘ 同上一个一样的作用 2、LOAD DATA LOCAL INFILE ‘event.txt‘ INTO TABLE event 将TXT文件 导入event表中 在Linux执行sql文件,source xxx.sql CREATE TABLE shop ( article INT(4) UNSIGNED ZEROFILL DEFAULT ‘0000‘ NOT NULL, dealer CHAR(20) DEFAULT ‘‘ NOT NULL, price DOUBLE(16,2) DEFAULT ‘0.00‘ NOT NULL, PRIMARY KEY(article, dealer)); INSERT INTO shop VALUES (1,‘A‘,3.45),(1,‘B‘,3.99),(2,‘A‘,10.99),(3,‘B‘,1.45), (3,‘C‘,1.69),(3,‘D‘,1.25),(4,‘D‘,19.95);
MySQL日常操作
标签:pat 安装 ase red source exp signed 1.4 ora