MySql基本命令

2022-07-15 09:45:12 字數 2039 閱讀 1769

登陸

1、登陸:mysql -uroot -p123456

database

1、檢視資料庫:show databases;

2、建立資料庫:create database test;

3、檢視資料庫資訊:show create database test;

4、選擇資料庫:use test;

5、刪除資料庫:drop database test;

檢視當前資料庫

1、status

2、select database();

3、show tables;#列名中in後面的名稱,例如:tables_in_test

4、show variables like '%table%';

tables

1、檢視資料庫表:show tables like '%dept%';

2、建立表:

create table `dept` (

`id` int(11) not null auto_increment,

`name` varchar(20) not null,

`bactive` tinyint(1) default '1',

primary key (`id`),

unique key `name` (`name`)

) engine=innodb default charset=utf8;

create table: create table `employee` (

`id` int(11) not null auto_increment,

`name` varchar(20) not null,

`deptid` int(11) default null,

primary key (`id`),

unique key `name` (`name`),

key `deptid` (`deptid`),

constraint `fk_employee_dept` foreign key (`deptid`) references `dept` (`id`)

) engine=innodb default charset=utf8;

注:外來鍵不能跨儲存引擎。

檢視表結構/索引

1、describe/desc

2、show create table employee\g;

3、show index from employee;

4、show keys from employee;

修改資料庫表

1、alter table employee rename t_employee;

2、alter table employee modify name varchar(25);

3、alter table employee change name cname varchar(20);

4、alter table employee add dcreatetime timestamp not null default current_timestamp;

5、alter table employee add/modify id int(11) first;alter table employee add/modify name varchar(20) after id;

6、alter table employee drop name;

7、alter table employee engine=myisam;

8、alter table employee drop foreign key fk_employee_dept;

刪除資料庫表

1、drop table if exists employee;

檢視鎖1、select * from information_schema.innodb_lock_waits g;

2、select * from information_schema.innodb_locks g;

3、select * from information_schema.innodb_trx g;

mysql基本命令總結 mysql基本命令總結

1.在ubuntu上安裝mysql sudo apt get install mysql server sudo apt get install mysql client 2.安裝結束後,用命令驗證是否安裝並啟動成功 sudo netstat tap grep mysql 通過上述命令檢查之後,如果...

mysql基本命令

第一招 mysql服務的啟動和停止 net stop mysql net start mysql 第二招 登陸mysql 語法如下 mysql u使用者名稱 p使用者密碼 鍵入命令mysql uroot p,回車後提示你輸入密碼,輸入12345,然後回車即可進入到mysql中了,mysql的提示符是...

mysql 基本命令

第一招 mysql服務的啟動和停止 net stop mysql net start mysql 第二招 登陸mysql 語法如下 mysql u使用者名稱 p使用者密碼 鍵入命令mysql uroot p,回車後提示你輸入密碼,輸入12345,然後回車即可進入到mysql中了,mysql的提示符是...