MYSQL基本語句

來源:互聯網
上載者:User

標籤:mysql語句

mysqladmin  -u root password ‘123‘ [[email protected] ~]# mysqladmin -u root password ‘123456‘    #明文設定密碼[[email protected] ~]# mysql -u root –p        #密文設定密碼設定密碼mysql -u root -p -h localhost 本地登入資料庫  -hshow databases;查看資料庫show tables;查看資料表;use 庫名;切換資料庫describe 表名;查看錶結構;

增:

create database 庫名;建立資料庫create table 表名 (欄位1 值,欄位2 值 ……);建立資料表insert into 表名 (欄位1,欄位2……) values (資料1,資料2……);插入資料create user 使用者名稱@登入地址 identified by ‘密碼‘建立使用者

刪:

drop database 庫名;刪除資料庫drop table 表名;刪除資料表delete from 表名;刪除表中所有資料delete from 表名 where 欄位刪除表中某條記錄

改:

update 表名 set 欄位1 where 欄位2 修改欄位1的資料update 表名 set 欄位1 where 欄位2 between num1 and num2修改從num1到num2之間的欄位的值grant 許可權 on 資料庫.資料表 to ‘使用者‘@‘地址‘;修改許可權revoke 許可權1,許可權2 on 資料庫.資料表 from ‘使用者‘@‘地址‘;取消許可權set password=password("密碼")修改管理員密碼或者普通使用者修改自身密碼set password for ‘使用者‘@‘地址‘=password("密碼")修改普通使用者密碼

查:

select 欄位 from 表名;查看錶內的資料

備份:

mysqldump -u root -p 資料庫 > 1.sql

備份資料庫到1.sql

mysql -u root -p < 1.sql

還原1.sql

mysqldump -u root -p 資料庫 資料表 > 2.sql

備份資料庫中的某表到2.sql

mysql -u root -p 資料庫 < 2.sql

還原資料表

mysqldump -u root -p --databases 資料庫1 資料庫2 > 3.sql

備份多個資料庫

mysql -u root -p < 3.sql

還原所有資料庫

mysql -u root -p --all-databases > 4.sql

備份所有資料庫

本文出自 “站在雲端” 部落格,請務必保留此出處http://9827789.blog.51cto.com/9817789/1664454

MYSQL基本語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.