您好,登錄后才能下訂單哦!
下文給大家?guī)?lái)關(guān)于mysql的相關(guān)設(shè)置總結(jié),感興趣的話就一起來(lái)看看這篇文章吧,相信看完mysql的相關(guān)設(shè)置總結(jié)對(duì)大家多少有點(diǎn)幫助吧。
1.安裝MySQL
使用管理員權(quán)限運(yùn)行以下語(yǔ)句獲取mysql以及Python編程接口;
apt-get install mysql-server python-mysqldb
在安裝的過(guò)程中會(huì)讓你輸入密碼,輸入數(shù)據(jù)庫(kù)的密碼就行。
2.測(cè)試MySQL
輸入以下指令對(duì)mysql測(cè)試,首先是進(jìn)入mysql(以用戶root登陸,會(huì)讓你輸入密碼,密碼輸入過(guò)程是不可見(jiàn)的,輸入完成后按回車就行):
mysql -u root -p
查看當(dāng)前的數(shù)據(jù)庫(kù):
show databases;
創(chuàng)建一個(gè)數(shù)據(jù)庫(kù):
create database dt_test;
使用dt_test數(shù)據(jù)庫(kù):
use dt_test;
查看數(shù)據(jù)庫(kù)中存在的表:
show tables;
創(chuàng)建一個(gè)表tbtest:
create table tbtest(id int,name varchar(20));
向tbtest表中插入數(shù)據(jù):
insert into tbtest values(1,'test');
查看tbtest表中的數(shù)據(jù):
select * from tbtest;
刪除dt_test數(shù)據(jù)庫(kù)中名稱為dttest的表格:
drop table tbtest;
刪除數(shù)據(jù)庫(kù)dt_test:
drop database dt_test;
退出:
quit
3.在MySQL中創(chuàng)建一個(gè)自增字段
crete table tb1(
id int auto_increment, //創(chuàng)建id為int型自增字段
name varchar(20) primary key, //設(shè)置name為主鍵
key(id)); //取消id主鍵
4.關(guān)于MySQL主鍵設(shè)置問(wèn)題
1、最簡(jiǎn)單的:
create table t1( id int not null, name char(20) );
2、帶主鍵的:
create table t1( id int not null primary key, name char(20) );
b:復(fù)合主鍵
create table t1( id int not null, name char(20), primary key (id,name) );
3、帶默認(rèn)值的:
create table t1( id int not null default 0 primary key, name char(20) default '1' );
5.更改表或者數(shù)據(jù)庫(kù)名稱
alter table oldtablename rename newtablename;
看了以上關(guān)于mysql的相關(guān)設(shè)置總結(jié)詳細(xì)內(nèi)容,是否有所收獲。如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。
免責(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)容。