mysql 存儲過程或函數(shù) split 怎么寫
網(wǎng)站的建設(shè)成都創(chuàng)新互聯(lián)專注網(wǎng)站定制,經(jīng)驗豐富,不做模板,主營網(wǎng)站定制開發(fā).小程序定制開發(fā),H5頁面制作!給你煥然一新的設(shè)計體驗!已為成都玻璃鋼雕塑等企業(yè)提供專業(yè)服務(wù)。
1、函數(shù)必須指定返回值,且參數(shù)默認為IN類型。
2、存儲過程沒返回值,參數(shù)可以是 IN,OUT,IN OUT類型,有的人可能會理解成OUT 也算是返回值。
3、調(diào)用方式:函數(shù) select my_fun() ;過程 call my_pro( ) ;
Mysql常用命令詳解
Mysql安裝目錄
數(shù)據(jù)庫目錄
/var/lib/mysql/
配置文件
/usr/share/mysql(mysql.server命令及配置文件)
相關(guān)命令
/usr/bin(mysqladmin mysqldump等命令)
啟動腳本
/etc/init.d/mysql(啟動腳本文件mysql的目錄)
系統(tǒng)管理
連接MySQL
格式:
mysql -h 主機地址 -u用戶名 -p用戶密碼
例 1:連接到本機上的 MySQL。
hadoop@ubuntu:~$ mysql
-uroot -pmysql;
例 2:連接到遠程主機上的 MYSQL。
hadoop@ubuntu:~$ mysql -h
127.0.0.1 -uroot -pmysql;
修改新密碼
在終端輸入:mysql -u用戶名 -p密碼,回車進入Mysql。
use mysql;
update user set password=PASSWORD('新密碼') where
user='用戶名';
flush privileges; #更新權(quán)限
quit; #退出
增加新用戶
格式:grant select on 數(shù)據(jù)庫.* to
用戶名@登錄主機 identified by '密碼'
舉例:
例 1:增加一個用戶 test1 密碼為
abc,讓他可以在任何主機上登錄,并對所有數(shù)據(jù)庫有
查詢、插入、修改、刪除的權(quán)限。首先用以 root 用戶連入
MySQL,然后鍵入以下命令:
mysqlgrant select,insert,update,delete on *.* to
root@localhost identified by 'mysql';
或者
grant all privileges on *.* to
root@localhost identified by 'mysql';
然后刷新權(quán)限設(shè)置。
flush privileges;
例
2:如果你不想 root 有密碼操作數(shù)據(jù)庫“mydb”里的數(shù)據(jù)表,可以再打一個命令將密碼消掉。
grant
select,insert,update,delete on mydb.* to root@localhost identified by
'';
刪除用戶
hadoop@ubuntu:~$ mysql
-u用戶名 -p密碼
mysqldelete from user where user='用戶名' and
host='localhost';
mysqlflush privileges;
//刪除用戶的數(shù)據(jù)庫
mysqldrop
database dbname;
數(shù)據(jù)庫操作
顯示所有的數(shù)據(jù)庫
mysql show databases;(注意:最后有個
s)
創(chuàng)建數(shù)據(jù)庫
mysql create database
test;
連接數(shù)據(jù)庫
mysql use
test;
查看當前使用的數(shù)據(jù)庫
mysql select
database();
當前數(shù)據(jù)庫包含的表信息
mysql
show tables; (注意:最后有個 s)
刪除數(shù)據(jù)庫
mysql drop database
test;
表操作
備注:操作之前使用“use
數(shù)據(jù)庫名”應(yīng)連接某個數(shù)據(jù)庫。
建表
命令:create
table 表名 (字段名 1 類型 1 [,..字段名 n 類型
n]);
例子:
mysql create table MyClass(
id int(4) not null
primary key auto_increment,
name char(20) not null,
sex int(4)
not null default '0',
degree double(16,2));
獲取表結(jié)構(gòu)
命令: desc 表名,或者show columns from
表名
例子:
mysql describe MyClass
mysql desc MyClass;
mysql
show columns from MyClass;
刪除表
命令:drop table 表名
例如:刪除表名為
MyClass 的表
mysql drop table MyClass;
插入數(shù)據(jù)
命令:insert into 表名 [( 字段名
1[,..字段名 n ])] values ( 值 1 )[, ( 值 n )]
例子:
mysql insert
into MyClass values(1,'Tom',96.45),(2,'Joan',82.99), (2,'Wang',
96.59);
查詢表中的數(shù)據(jù)
查詢所有行
mysql
select * from MyClass;
查詢前幾行數(shù)據(jù)
例如:查看表 MyClass 中前 2 行數(shù)據(jù)
mysql
select * from MyClass order by id limit 0,2;
或者
mysql select * from
MyClass limit 0,2;
刪除表中數(shù)據(jù)
命令:delete from 表名 where 表達式
例如:刪除表
MyClass 中編號為 1 的記錄
mysql delete from MyClass where id=1;
修改表中數(shù)據(jù)
命令:update 表名 set 字段=新值,... where
條件
mysql update MyClass set name='Mary' where id=1;
在表中增加字段
命令:alter table 表名 add 字段 類型
其他;
例如:在表 MyClass 中添加了一個字段 passtest,類型為 int(4),默認值為 0
mysql alter
table MyClass add passtest int(4) default '0'
更改表名
命令:rename table 原表名 to 新表名;
例如:在表
MyClass 名字更改為 YouClass
mysql rename table MyClass to
YouClass;
更新字段內(nèi)容
命令:update 表名 set
字段名 = 新內(nèi)容
update 表名 set 字段名 = replace(字段名, '舊內(nèi)容', '新內(nèi)容');
例如:文章前面加入 4
個空格
update article set content=concat(' ', content);
數(shù)據(jù)庫導(dǎo)入導(dǎo)出
從數(shù)據(jù)庫導(dǎo)出數(shù)據(jù)庫文件
使用“mysqldump”命令
首先進入 DOS
界面,然后進行下面操作。
1)導(dǎo)出所有數(shù)據(jù)庫
格式:mysqldump -u [數(shù)據(jù)庫用戶名] -p
-A[備份文件的保存路徑]
2)導(dǎo)出數(shù)據(jù)和數(shù)據(jù)結(jié)構(gòu)
格式:mysqldump -u [數(shù)據(jù)庫用戶名] -p
[要備份的數(shù)據(jù)庫名稱][備份文件的保存路徑]
舉例:
例 1:將數(shù)據(jù)庫 mydb 導(dǎo)出到 e:\MySQL\mydb.sql
文件中。
打開開始-運行-輸入“cmd”,進入命令行模式。
c:\ mysqldump -h localhost -u
root -p mydb e:\MySQL\mydb.sql
然后輸入密碼,等待一會導(dǎo)出就成功了,可以到目標文件中檢查是否成功。
例
2:將數(shù)據(jù)庫 mydb 中的 mytable 導(dǎo)出到 e:\MySQL\mytable.sql 文件中。
c:\ mysqldump -h
localhost -u root -p mydb mytablee:\MySQL\mytable.sql
例 3:將數(shù)據(jù)庫 mydb
的結(jié)構(gòu)導(dǎo)出到 e:\MySQL\mydb_stru.sql 文件中。
c:\ mysqldump -h localhost -u root -p
mydb --add-drop-table e:\MySQL\mydb_stru.sql
備注:-h localhost
可以省略,其一般在虛擬主機上用。
3)只導(dǎo)出數(shù)據(jù)不導(dǎo)出數(shù)據(jù)結(jié)構(gòu)
格式:
mysqldump -u [數(shù)據(jù)庫用戶名] -p -t
[要備份的數(shù)據(jù)庫名稱][備份文件的保存路徑]
4)導(dǎo)出數(shù)據(jù)庫中的Events
格式:mysqldump -u [數(shù)據(jù)庫用戶名] -p
-E [數(shù)據(jù)庫用戶名][備份文件的保存路徑]
5)導(dǎo)出數(shù)據(jù)庫中的存儲過程和函數(shù)
格式:mysqldump -u [數(shù)據(jù)庫用戶名]
-p -R [數(shù)據(jù)庫用戶名][備份文件的保存路徑]
從外部文件導(dǎo)入數(shù)據(jù)庫中
1)使用“source”命令
首先進入“mysql”命令控制臺,然后創(chuàng)建數(shù)據(jù)庫,然后使用該數(shù)據(jù)庫。最后執(zhí)行下面操作。
mysqlsource
[備份文件的保存路徑]
2)使用“”符號
首先進入“mysql”命令控制臺,然后創(chuàng)建數(shù)據(jù)庫,然后退出 MySQL,進入 DOS
界面。最后執(zhí)行下面操作。
mysql -u root –p [備份文件的保存路徑]
在where條件中,每個條件之間的鏈接可以用and或or。or就是或的意思,但注意要放在最后一個條件中,不然會有問題的。
用 or (或),and(且)來寫
三個之中 : df 電費 fz 房租 sf 水費
兩個為 0 另一個 不為 0,(可設(shè)置為大于 0)
select * from table _ name where fz = 0 and sf = 0 and df 0 or
fz = 0 and df = 0 and sf 0 or df = 0 and sf = 0 and fz 0
名稱欄目:mysql怎么寫或 mysql怎么寫入數(shù)據(jù)
URL地址:http://vcdvsql.cn/article0/dopepoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、網(wǎng)站導(dǎo)航、手機網(wǎng)站建設(shè)、全網(wǎng)營銷推廣、搜索引擎優(yōu)化、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)