資料庫 mysql 操作

2022-03-04 13:37:57 字數 2435 閱讀 7240

安裝好xammp,開啟阿帕奇和資料庫服務;

點選右側 shell 按鈕,進入命令列;

首先,利用超級管理員許可權進入資料庫: mysql -uroot -p

enter,再enter

把下述**複製進命令列,或者把下述**儲存到乙個檔案,檔名為英文,路徑也為英文,比如:test.sql

然後在命令列寫入:

source c:\xampp\htdocs\ajax\07.13\test\test.sql

在瀏覽器視窗輸入:

上述**中:

set names utf8; //設定編碼格式utf-8

drop database if exists t0713; //刪除資料庫,如果存在t0713資料庫

create database t0713 charset = utf8; //建立資料庫t0713,並設定編碼utf-8

use t0713; //用這個資料庫

create table t_user( //建立資料表

id int primary key auto_increment, //設定id為自增長,**為:int primary key auto_increment

pname varchar(32), //使用者名稱採用字串32位

pwd varchar(32) //密碼採用字串32位

); insert into t_user values //向資料表中插入資料

(null,』tom』,』123456』),

(null,』jack』,』123456』),

(null,』lose』,』123456』);

列資料型別(常用列型別)

int 整型(年齡) 範圍-21億~21億

varchar(10) 字串(10個字元[數字,字母,漢字])

double(10,2) 浮點(小數)總長10位其中2位小數

datetime 日期和時間

bigint 計算機最大值

varchar(3) not null default 」 沒有就預設為空

插入完,我們可以在命令列,查詢資料

mysql -uroot -p

show databases;

use t0713;

show tables;

select * from t_user;

上面講到向資料庫新增記錄,下面說說刪除記錄

刪除資料表:

drop table t_user;

刪除資料表中某行的資料:

delete from 表名 where 條件;

delete from t_user where id=3; (一般都用id,效率高)

delete from t_user where pname=』jack』;

更新記錄:

update 表名 set 列名1=新值1,列名2=新值2 where 條件;

update t_user set pname=』bob』 where id=1;

查詢記錄:

select 列名1,列名2,… from 表名 where 條件;

select * from 表名 where 條件; // * 代表所有列

公升序:select * from t_emp order by sal;

降序:select * from t_emp order by sal desc;

子查詢

select * from t_temp where did = (select id from t_dept where name = 『account』);

mysql資料庫核對 Mysql資料庫操作總結

1 部署資料庫服務 mariadb yum install y mariadb 運算元據庫命令 mariadb server 啟動資料庫服務 systemctl startmariadb 建立資料庫 create database 資料庫名 建立好資料庫之後可以檢視資料庫是否建立 show data...

mysql資料庫基本操作 MYSQL資料庫基本操作

1.連線mysql mysql u 使用者名稱 p 回車後要求輸入密碼,密碼不可見 2.退出mysql命令 exit 回車 3.修改密碼 mysqladmin u使用者名稱 p舊密碼 password 新密碼4.檢視mysql許可權和使用者select host,user fromuser 對資料庫...

mysql資料庫語法 MySQL資料庫操作語法詳解

1 資料庫建立 建庫語句如下 create database schema會建立乙個給定名稱的資料庫,只有擁有create許可權才能使用該語法。不加if not exists時,如果需要建立資料庫已經同名存在則會報錯。create specification中指定了建立資料庫特性。資料庫特性存放在資...