mysql基本操作

2022-05-07 04:33:07 字數 1862 閱讀 6075

建立庫:create database test1 charset utf8;

檢視庫:show databases;

檢視創庫語句:show create database test1;

選擇庫:use test1

修改庫:alter database test1 charset utf8mb4;

刪除庫:drop database test1;

建立表:create table stu (id int,name varchar(10));

建立相同表結構的表:create table stu1 like stu;

建立乙個相同的備用表:create table stu2 as select * from stu;

檢視表:show tables;

檢視創表語句:show create table stu;

檢視表結構:desc stu;

修改表名:alter table stu rename to student;

刪除表:drop table stu;

刪除大表:truncate table stu;(對於很大的錶用drop刪慢,可以先用truncate再用drop)

alter修改表:

1.在表最後加一列:alter table student add addr varchar(20);

2.在表頭部加一列:alter table student add stu_id int first;

3.在name列後加一列:alter table student add qq int after name;

4.在age後加tel_num,在最後一行加email:alter table student add tel_num int after age,add email varchar(20);

5.刪除某一列:alter table student drop id;

6.修改列名字:alter table student change name stu_name varchar(20);

7.修改列資料型別:alter table student modify gender varchar(20);

insert向表中插入資料:

1.插入單行:insert [into] student values(1,'beizi',111,20,110,'male','bj','[email protected]');

2.指定列進行插入:insert into student(stu_id,stu_name,qq) values(2,'li4',456);

3.多行插入:insert into student values(1,'zhang3',123,20,110,'male','bj','[email protected]'),(5,'zz',12322,202,1102,'female','bj','[email protected]');

4.乙個表向另乙個表插入:insert into stu0 select * from student;(表結構要一樣)

update修改表資料:

修改一行:update student set stu_name='zhangsan' where stu_id=1;

delete刪除表資料:

delete from student where stu_name='zhangsan';

注:delete刪除比較危險,可以用識別符號配合update進行偽刪除:

alter table stu0 add state int default 1;

update stu0 set state=0 where stu_name='zhangsan';

select * from stu0 where state=1;

select查詢語句詳解下次繼續

mysql基本操作 MySQL基本操作

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 1.1 登入mysql mysql u root p 密碼 1.2 建立使用者 mysql insert into mysql.user host,user,passwor...

mysql 基本操作 mysql基本操作

mysql 建立表,並設定主鍵自增 create table log logid int 4 primary key not null auto increment,logtitle varchar 32 not null logcontent varchar 160 not null logtim...

mysql基本操作

1,檢視資料庫狀態 及啟動停止 etc init.d mysqld status etc init.d mysqld start etc init.d mysqld stop 2,給使用者配置初始密碼123456 mysqladmin u root password 123456 3,修改root使...