mysql建表常用sql語句個人經驗分享

2022-09-29 05:18:08 字數 1420 閱讀 4875

斷開:exit (回車)

建立授權:grant select on 資料庫.* to 使用者名稱@登入主機 identified by \"密碼\"

修改密碼:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼

刪除授權: revoke select,insert,update,d程式設計客棧elete om *.* from test2@localhost;

顯示資料庫:show databases;

顯示資料表:show tables;

顯示表結構:describe 表名;

建立庫:create database 庫名;

刪除庫:drop database 庫名;

使用庫(選中庫):use 庫名;

建立表:create table 表名 (字段設定列表);

刪除表:drop table 表名;

修改表:alter table t1 rename t2

查詢表:select * from 表名;

清空表:delete from 表名;

備份表: mysqlbinmysqldump -h(ip) -uroot -p(password) databasename table > tablename.sql

恢復表: mysqlbinmysql -h(ip) -uroot -p(password) databasename tablename < tablenam程式設計客棧e.sql(操作前先把原來表刪除)

增加列:alter table t2 add c程式設計客棧 int unsigned not null auto_increment,add index (c);

修改列:alter table t2 modify a tinyint not null, change b c char(20);

刪除列:alter table t2 drop column c;

備份資料庫:mysql\bin\程式設計客棧mysqldump -h(ip) -uroot -p(password) databasename > database.sql

恢復資料庫:mysql\bin\mysql -h(ip) -uroot -p(password) databasename < database.sql

複製資料庫:mysql\bin\mysqldump --all-databases > all-databases.sql

修復資料庫:mysqlcheck -a -o -uroot -p54safer

文字資料匯入: load data local infile \"檔名\" into table 表名;

資料匯入匯出:mysql\bin\mysqlimport database tables.txt

本文標題: mysql建表常用sql語句個人經驗分享

本文位址:

建表mysql語句嗎 關於MySQL語句建表的總結

在寫 之前,需要注意的乙個問題是,使用命令列模式寫 mysql 語句,如果涉及到中文,最好利用 mysql charset gbk 命令將客戶端字符集設定為 gbk,這樣能保證正確插入和讀 取中文資料庫端字符集可以是 gb2312,gbk,utf8 等支援中文的字符集 如果是利用 mysql 提供的...

SQL語句建表等

以下就是示例 用 ddl 的 create table 建立乙個表 table1 主鍵是自動編號字段,另乙個欄位是長度是 10 的文字字段。create table table1 id counter constraint primarykey primary key,mytext text 10 ...

sql中建庫建表的sql語句

建庫 use master goif exists select from sysdatabases where name news drop database news gocreate database news on primary name news filename f dbproject...