標籤:arc SQ utf8 alter 條件 str sele 修改表 修改
在ubuntu系統中操作命令:
登入:mysql -uroot -p
啟動:service mysql start
停止:service mysql stop
重啟:service mysql restart
建立資料庫:create database 資料庫名字 charset = utf8;
刪除資料庫:drop database 資料庫名字;
查看所有資料庫:show databases;
使用資料庫:use 資料庫名字;
查看當前使用的資料庫:select database();
更改資料庫密碼:update mysql.user set authentication_string=password(‘root‘) where user=‘root‘;
建表命令:
create table 表名(列。。。);
唯一的標識(主鍵):id,
類型:int unsigned,
約束1:not null,
約束2:auto_increment,
約束3:primary key
列的格式:列的名字,類型,約束
如:
create table students(
id int auto_increment primary key not null,
name varchar(10),
gender bit default 1,
birthday datetime,
isDelete bit default 0
);
查看所有表:show tables;
查看錶結構:desc 表名;
修改表:alter table 表名 add|modify|drop 列名 類型 約束;
alter table students modify column isDelete bit not null default 0;
更改表名:rename table 原表名 to 新表名;
刪除表:drop table 表名;
查看錶的建立語句:show create table ‘表名‘;
添加資料:insert into table 表名(列名) values(值),(值)。。。;
修改資料:update 表名 set 列1 = 值1。。。where 條件;
刪除資料:delete from 表名 where 條件;
一般不做物理刪除,做邏輯刪除;
邏輯刪除:update。。。;
備份:mysqldump -uroot -p 資料庫名> 檔案名稱.sql
恢複:mysql -uroot -p 資料庫名< 檔案名稱.sql
MySQL基本命令1