MySQL基本命令1

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.