mysql創(chuàng)建表的sql語句詳細總結(jié)
mysql創(chuàng)建表的sql語句
mysql建表常用sql語句:
連接:mysql -h主機地址 -u用戶名 -p用戶密碼 (注:u與root可以不用加空格,其它也一樣)
斷開:exit (回車)
創(chuàng)建授權(quán):grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by \"密碼\"
修改密碼:mysqladmin -u用戶名 -p舊密碼 password 新密碼
刪除授權(quán): revoke select,insert,update,delete om *.* from test2@localhost;
顯示數(shù)據(jù)庫:show databases;
顯示數(shù)據(jù)表:show tables;
顯示表結(jié)構(gòu):describe 表名;
創(chuàng)建庫:create database 庫名;
刪除庫:drop database 庫名;
使用庫(選中庫):use 庫名;
創(chuàng)建表:create table 表名 (字段設(shè)定列表);
刪除表:drop table 表名;
修改表:alter table t1 rename t2
查詢表:select * from 表名;
清空表:delete from 表名;
備份表: mysqlbinmysqldump -h(ip) -uroot -p(password) databasename tablename > tablename.sql
恢復(fù)表: mysqlbinmysql -h(ip) -uroot -p(password) databasename tablename < tablename.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;
備份數(shù)據(jù)庫:mysql\bin\mysqldump -h(ip) -uroot -p(password) databasename > database.sql
恢復(fù)數(shù)據(jù)庫:mysql\bin\mysql -h(ip) -uroot -p(password) databasename < database.sql
復(fù)制數(shù)據(jù)庫:mysql\bin\mysqldump --all-databases > all-databases.sql
修復(fù)數(shù)據(jù)庫:mysqlcheck -A -o -uroot -p54safer
文本數(shù)據(jù)導(dǎo)入: load data local infile \"文件名\" into table 表名;
數(shù)據(jù)導(dǎo)入導(dǎo)出:mysql\bin\mysqlimport database tables.txt
以上就是mysql創(chuàng)建表的sql語句的詳細內(nèi)容,知識點很簡單,希望腳本之家整理的內(nèi)容能夠幫助到大家。
相關(guān)文章
MySQL數(shù)據(jù)庫自增主鍵的間隔不為1的解決方式
這篇文章主要介紹了MySQL數(shù)據(jù)庫自增主鍵的間隔不為1的解決方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12MySQL數(shù)據(jù)庫-錯誤1166 Incorrect column name
這篇文章主要介紹了MySQL數(shù)據(jù)庫-錯誤1166 Incorrect column name,需要的朋友可以參考下2016-04-04Mysql啟動與數(shù)據(jù)庫的創(chuàng)建方法[圖文]
Mysql啟動與數(shù)據(jù)庫的創(chuàng)建方法,mysql數(shù)據(jù)庫入門2012-03-03mysql自動定時備份數(shù)據(jù)庫的最佳方法(windows服務(wù)器)
網(wǎng)上有很多關(guān)于window下Mysql自動備份的方法,可是真的能用的也沒有幾個,有些說的還非常的復(fù)雜,難以操作,這里腳本之家小編為大家分享與整理了幾個軟件方便大家使用2016-11-11MySQL優(yōu)化總結(jié)-查詢總條數(shù)
這篇文章主要介紹了MySQL優(yōu)化總結(jié)-查詢總條數(shù)的相關(guān)內(nèi)容,文中進行簡單的測試對比,具有一定參考價值,需要的朋友可以了解下。2017-10-10解析MYSQL 數(shù)據(jù)庫導(dǎo)入SQL 文件出現(xiàn)亂碼的問題
本篇文章是對MYSQL數(shù)據(jù)庫導(dǎo)入SQL文件出現(xiàn)亂碼的問題進行了詳細的分析介紹,需要的朋友參考下2013-06-06