`
- 浏览:
245707 次
-
今天找到了一个好贴,已经可以解决上面的问题了,和兄弟们一起分享一下
[以下内容转自 程序员大本营 2004-02-02]
Peeking in MySQL5.0 alpha Enterprise Functional<Function & Procedure>;
程序员大本营 2004-02-02
MySQL5.0 Alpha 發佈, 我們期待已久的 Create Function 和 Create Procedure 的功能終於有了. 詳細的資訊請參考 MySQL AB 的官方網站的 新聞. 早就想要的功能,出來了還不趕快試試....
本文以 Windows XP PRO os 為例< 我可不是有意來替 M$ 宣傳,只是我用的是 Windows,沒有辦法啦>;來說明,其它OS 類同, 先下載 MySQL5.0, 為了免除安裝,我們直接下載 Without installer (unzip in C:\) 的版本,到 http://www.mysql.com/downloads/mysql-5.0.html 下載.
1. 直接 unzip 後把其放到 C:\ 下, 並把 root Directory 改為 mysql(不改也可,那在 my.ini 中要把其中的 mysql 改為你的實際名稱)
2. 下面是 my.ini 的配置文件,如果你對配置不熟的話,你可以直接 Copy 過去存為 my.ini 後放到 C:\windows 下即可 (我電腦的 RAM = 256)
========================================================================================================
# Example mysql config file.
# Copy this file to c:\my.cnf to set global options
#
# One can use all long options that the program supports.
# Run the program with --help to get a list of available options
# This will be passed to all mysql clients
[client]
#password=my_password
port=3306
#socket=MySQL
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# The MySQL server
[mysqld]
port=3306
#socket=MySQL
skip-locking
set-variable = key_buffer=16M
set-variable = max_allowed_packet=1M
set-variable = table_cache=64
set-variable = sort_buffer=512K
set-variable = net_buffer_length=8K
set-variable = myisam_sort_buffer_size=8M
server-id = 1
# Uncomment the following if you want to log updates
#log-bin
# Uncomment the following rows if you move the MySQL distribution to another
# location
#basedir = d:/mysql/
#datadir = d:/mysql/data/
# Uncomment the following if you are NOT using BDB tables
#skip-bdb
# Uncomment the following if you are using BDB tables
#set-variable = bdb_cache_size=4M
#set-variable = bdb_max_lock=10000
# Uncomment the following if you are using Innobase tables
innodb_data_file_path = ibdata1:400M
innodb_data_home_dir = C:/mysql/InnoDB/ibdata # InnoDB 及 ibdata 的資料夾你要自己動手
innodb_log_group_home_dir = C:/mysql/InnoDB/iblogs # iblogs 的資料夾同樣你要自己動手
innodb_log_arch_dir = C:/mysql/innodb/iblogs
set-variable = innodb_mirrored_log_groups=1
set-variable = innodb_log_files_in_group=3
set-variable = innodb_log_file_size=5M
set-variable = innodb_log_buffer_size=8M
innodb_flush_log_at_trx_commit=1
innodb_log_archive=0
set-variable = innodb_buffer_pool_size=16M
set-variable = innodb_additional_mem_pool_size=2M
set-variable = innodb_file_io_threads=4
set-variable = innodb_lock_wait_timeout=50
[mysqldump]
quick
set-variable = max_allowed_packet=16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[isamchk]
set-variable = key_buffer=20M
set-variable = sort_buffer=20M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[myisamchk]
set-variable = key_buffer=20M
set-variable = sort_buffer=20M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[mysqlhotcopy]
interactive-timeout
[WinMySQLAdmin]
Server=C:/mysql/bin/mysqld-nt.exe
============================================================================
3. Create InnoDB table table space 如果運行沒有問題,你應該可以看到如下內容:
==========================================================
C:\mysql\bin>;mysqld --console
InnoDB: The first specified data file C:\mysql\InnoDB\ibdata\ibdata1 did not exist:
InnoDB: a new database to be created!
040113 15:12:54 InnoDB: Setting file C:\mysql\InnoDB\ibdata\ibdata1 size to 400 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200 300 400
040113 15:13:19 InnoDB: Log file C:\mysql\InnoDB\iblogs\ib_logfile0 did not exist: new to be created
InnoDB: Setting log file C:\mysql\InnoDB\iblogs\ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
040113 15:13:19 InnoDB: Log file C:\mysql\InnoDB\iblogs\ib_logfile1 did not exist: new to be created
InnoDB: Setting log file C:\mysql\InnoDB\iblogs\ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
040113 15:13:20 InnoDB: Log file C:\mysql\InnoDB\iblogs\ib_logfile2 did not exist: new to be created
InnoDB: Setting log file C:\mysql\InnoDB\iblogs\ib_logfile2 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
040113 15:13:26 InnoDB: Started; log sequence number 0 0
mysqld: ready for connections.
Version: '5.0.0-alpha-max-debug' socket: '' port: 3306
==========================================================
安裝 Ok, 進去看看吧,沒想到一進 Mysql 馬上就來了個下馬威, 原來的 '' 這個 user 不能用 mysql 的 databases
=========================================================
C:\mysql\bin>;mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.0-alpha-max-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>; use mysql
ERROR 1044 (42000): Access denied for user: ''@'localhost' to database 'mysql
==========================================================
沒有辦法,只有用 root 進去:
==========================================================
C:\mysql\bin>;mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.0-alpha-max-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>;
==========================================================
root 的密碼還是勤快一點把它改掉吧
4. 體驗一下 Create Function 吧
CREATE FUNCTION MyFunc (s CHAR(20)) RETURNS CHAR(50) RETURN CONCAT('Hello ',s,' DLL',' !');
==========================================================
mysql>; CREATE FUNCTION MyFunc (s CHAR(20)) RETURNS CHAR(50) RETURN CONCAT('Hello
',s,'.Lan',' !');
Query OK, 0 rows affected (0.00 sec)
mysql>;
mysql>; select MyFunc('Dennis');
+--------------------+
| MyFunc('Dennis') |
+--------------------+
| Hello Dennis.Lan ! |
+--------------------+
1 row in set (0.01 sec)
mysql>;
==========================================================
5. Drop Function
==========================================================
mysql>; drop function MyFunc;
Query OK, 0 rows affected (0.00 sec)
mysql>;
==========================================================
6. Create 一個 Procedure 試試吧!
CREATE PROCEDURE MyProc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param1 FROM sys_forms; END;
千萬記住,下面這樣子不行喲, 我試了 n 次, 每次都是錯誤, 我還以為 Mysql 有問題呢,原來不是
==========================================================
mysql>; use test;
Database changed
mysql>; CREATE PROCEDURE MyProc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param
1 FROM sys_forms; END;
ERROR 1064 (42000): You have an error in your SQL syntax. Check the manual that
corresponds to your MySQL server version for the right syntax to use near 'SELE
CT COUNT(*) INTO param1 FROM sys_forms' at line 1
==========================================================
正確的做法是:
==========================================================
mysql>; delimiter | # 因為你的 Procedure 或 Function中難免會用到 ";" 作為 sql statement 的結束符, 所以還是請你把這個結束符號改一下吧,不然就會出現上面的 error 1064(42000)
mysql>; CREATE PROCEDURE MyProc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param1 FROM mysql.user; END;
->; |
Query OK, 0 rows affected (0.00 sec)
==========================================================
OK, 你的成功了嗎?
強烈建議你先看看這個 http://www.mysql.com/doc/en/CREATE_PROCEDURE.html
Procedure Create 成功了,測試一下吧!
Step 1:
==========================================================
mysql>; CALL MyProc(@a)|
Query OK, 0 rows affected (0.01 sec)
==========================================================
Step 2:
==========================================================
mysql>; select @a;
->; |
+------+
| @a |
+------+
| 0 |
+------+
1 row in set (0.00 sec)
mysql>;
==========================================================
來個完整的:
==========================================================
mysql>; CREATE PROCEDURE MyProc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param
1 FROM mysql.user; END;
->; |
Query OK, 0 rows affected (0.00 sec)
mysql>; call MyProc(@a)|
Query OK, 0 rows affected (0.03 sec)
mysql>; select @a |
+------+
| @a |
+------+
| 4 |
+------+
1 row in set (0.00 sec)
==========================================================
7. Drop Procedures:
這樣子做怎麼又不對呀?
==========================================================
mysql>; drop procedure myproc;
->; |
ERROR 1289 (42000): PROCEDURE myproc does not exist
==========================================================
原來 Windows 下的 MySQL 在 Procedure 的問題上又區分起輩份的大小了,下面這樣才對啊!
==========================================================
mysql>; drop procedure MyProc|
Query OK, 0 rows affected (0.00 sec)
==========================================================
注: 如果你在和應用程式連結的時候出現
Client does not support authentication protocol requested by server; consider upgrading MySQL client
請參考 http://www.mysql.com/doc/en/Old_client.html 這里提供了詳細的解決方案.
Enjoy it yourself!
Good Luck!
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
MySQL 5.0存储过程 mysql5.0 mysql 用户手册 中文版 新特性
SQL语句需要先编译然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给定参数(如果该存储过程带有参数)来调用执行它。...
MySQL 5.0存储过程是数据库管理中的一个重要概念,它是一种预编译的SQL语句集合,可以在数据库中被封装并作为一个独立的可执行单元。存储过程极大地提高了数据库的性能和安全性,因为它减少了网络流量,使得多次使用...
MySQL5.0 存储过程教程
在《MySQL中文参考手册.chm》中,你可以找到关于MySQL 5.0存储过程的详细文档,包括语法、示例、以及如何调试和优化存储过程。通过深入学习这本手册,你将能够更好地掌握存储过程的各个方面,提升你在数据库开发和...
### MySQL 5.0 存储过程核心知识点详解 #### 引言 随着数据库技术的发展,MySQL 5.0 版本引入了一系列重要的新特性,其中最值得关注的是**存储过程**的功能增强。这一功能不仅提高了数据库操作的灵活性,还极大地...
根据提供的文档信息,本文将深入解析《MySQL 5.0 存储过程》这一主题,重点探讨存储过程的概念、特点以及在 MySQL 5.0 中的应用。存储过程是数据库管理系统中一项重要的功能,它允许开发者编写可重用的 SQL 代码块,...
MySQL 5.0 存储过程是数据库管理系统中一种强大的功能,它允许用户编写一系列的SQL语句并封装成一个可重用的程序单元。在本文中,我们将深入探讨存储过程的基本概念、创建、调用、删除以及一些关键特性。 **一、...
CallableStatement 调用mysql5.0的存储过程和方法 配有创建存储过程和方法的源代码
通过了解和掌握这些特性,开发者能够更有效地利用MySQL 5.0存储过程来构建高效、可靠的数据库应用。提供的"procedure.pdf"文件很可能包含了更深入的存储过程使用指南和实例,建议详细阅读以深入理解这些概念和技巧。
在本场景中,我们关注的是PowerDesigner16.5版本与MySQL5.0模型的相关性。通常,PowerDesigner会包含多种数据库管理系统的模型支持,以适应不同数据库平台的需求。然而,有些用户在使用PowerDesigner16.5时可能会...
MySQL存储过程是数据库管理系统中的一个重要组成部分,特别是在MySQL 5.0版本中,它提供了一种组织和执行复杂SQL语句的高效方式。本资料集合包含了对MySQL 5.0官方存储过程的详细翻译,旨在帮助学习者深入理解并熟练...
- 存储过程和视图:创建、管理和使用存储过程和视图的方法。 #### 3. **管理与维护** - **服务器选项/变量参考** - 列出MySQL服务器可以接受的所有配置选项和运行时变量,并解释其功能。 - **安全** - 讨论...
MySQL 5.0是MySQL数据库管理系统的一个早期版本,它在当时提供了可靠且高效的数据存储解决方案。MySQL是一款开源的关系型数据库管理系统(RDBMS),由瑞典的MySQL AB公司开发,后来被Oracle公司收购。它的设计目标是...