溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

mysql的相關(guān)設(shè)置總結(jié)

發(fā)布時(shí)間:2020-06-03 17:37:41 來(lái)源:網(wǎng)絡(luò) 閱讀:169 作者:三月 欄目:數(shù)據(jù)庫(kù)

下文給大家?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è)資訊板塊。

向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI