您好,登錄后才能下訂單哦!
本文主要給大家介紹mysql創(chuàng)建數(shù)據(jù)庫(kù)的基本命令,其所涉及的東西,從理論知識(shí)來獲悉,有很多書籍、文獻(xiàn)可供大家參考,從現(xiàn)實(shí)意義角度出發(fā),億速云累計(jì)多年的實(shí)踐經(jīng)驗(yàn)可分享給大家。
一、創(chuàng)建數(shù)據(jù)庫(kù):
create database database_name;
切入數(shù)據(jù)庫(kù):
use database_name
php中創(chuàng)建數(shù)據(jù)庫(kù)的兩種方法:
(mysql_create_db(),mysql_query())
$conn = mysql_connect(“l(fā)ocalhost”,”username”,”password”) or
die ( “could not connect to localhost”);
1.
mysql_create_db(“database_name”) or
die (“could not create database”);
2.
$string = “create database database_name”;
mysql_query( $string) or
die (mysql_error());
二、選定數(shù)據(jù)庫(kù)
在創(chuàng)建表之前,必須要選定要?jiǎng)?chuàng)建的表所在的數(shù)據(jù)庫(kù)
選定數(shù)據(jù)庫(kù):
通過命令行客戶端:use database_name
通過php: mysql_select_db()
$conn = mysql_connect(“l(fā)ocalhost”,”username”,”password”) or
die ( “could not connect to localhost”);
mysql_select_db(“test”,$conn) or
die (“could not select database”);
三、建表
create table table_name
如:
create table table_name
(
column_1 column_type column attributes,
column_2 column_type column attributes,
column_3 column_type column attributes,
primary key (column_name),
index index_name(column_name)
)
在命令行客戶端需要鍵入整個(gè)命令
在php中使用,mysql_query()函數(shù)
如:
$conn = mysql_connect(“l(fā)ocalhost”,”username”,”password”) or
die ( “could not connect to localhost”);
mysql_select_db(“test”,$conn) or
die (“could not select database”);
$query = “create table my_table (col_1 int not null primary key,
col_2 text
)”;
mysql_query($query) or
die (mysql_error());
四、刪除表、數(shù)據(jù)庫(kù)
drop table table_name
drop database database_name
在php中可以通過mysql_query()函數(shù)使用drop table命令
在php中刪除數(shù)據(jù)庫(kù)需要使用mysql_drop_db()函數(shù)
五、列出數(shù)據(jù)庫(kù)中所有可用表(show tables)
注意:使用該命前必須先選定數(shù)據(jù)庫(kù)
在php中,可以使用mysql_list_tables()得到表中的清單
六、查看列的屬性和類型
show columns from table_name
show fields from table_name
使用mysql_field_name()、mysql_field_type()、mysql_field_len()可以得到類似信息!
七、查看參數(shù)信息
查看全局參數(shù):show global variables like '%關(guān)鍵字%';
查看局部參數(shù):show variables like '%關(guān)鍵字%';
八、查看數(shù)據(jù)庫(kù)bin-log日志信息
[root@localhost][db1]> show master logs;
+------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 3530 | +------------------+-----------+ 1 row in set (0.00 sec) [root@localhost][db1]> flush logs; Query OK, 0 rows affected (0.05 sec) [root@localhost][db1]> show master logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 3577 | | mysql-bin.000002 | 234 | +------------------+-----------+ 2 rows in set (0.00 sec) [root@localhost][db1]> PURGE BINARY LOGS TO 'mysql-bin.000002'; Query OK, 0 rows affected (0.01 sec) [root@localhost][db1]> show master logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000002 | 234 | +------------------+-----------+
1 row in set (0.00 sec)
看了以上介紹mysql創(chuàng)建數(shù)據(jù)庫(kù)的基本命令,希望能給大家在實(shí)際運(yùn)用中帶來一定的幫助。本文由于篇幅有限,難免會(huì)有不足和需要補(bǔ)充的地方,大家可以繼續(xù)關(guān)注億速云行業(yè)資訊板塊,會(huì)定期給大家更新行業(yè)新聞和知識(shí),如有需要更加專業(yè)的解答,可在官網(wǎng)聯(lián)系我們的24小時(shí)售前售后,隨時(shí)幫您解答問題的。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。