顯示具有 MySQL 標籤的文章。 顯示所有文章
顯示具有 MySQL 標籤的文章。 顯示所有文章

2012年8月3日 星期五

MYSQL 重覆資料怎麼刪除

這次又遇到一樣的問題了,key沒處理好,造成會有重複的資料

搜尋了一下,有看到幾種做法
1.直接刪掉在talbe裡重複的資料
例:ALTER IGNORE TABLE `資料表名稱` ADD UNIQUE INDEX(`欄位1`,`欄位2`...);

2.分二次,將 重複的資料 以及 未重複的資料 分別匯入另一個表,然後直接取代舊表

 我採用了以下的方式(較安全,雖然慢了一點) 
1.先將"未重複"的資料寫到另一個表 INSERT INTO `table_copy` SELECT * FROM `table` GROUP BY `field name` HAVING count(*)=1 
2.再將"重複"的資料寫到另一個表 INSERT INTO `table_copy` SELECT * FROM `table` GROUP BY `field name` HAVING count(*)>1 
3.直接用新表取代舊的表 

參考資料來源 
1、從MYSQL資料庫中找出重複的資料並刪除
2、[MYSQL]利用 SQL 找出欄位值重覆的記錄
這次又遇到一樣的問題了,key沒處理好,造成會有重複的資料

搜尋了一下,有看到幾種做法
1.直接刪掉在talbe裡重複的資料
例:ALTER IGNORE TABLE `資料表名稱` ADD UNIQUE INDEX(`欄位1`,`欄位2`...);

2.分二次,將 重複的資料 以及 未重複的資料 分別匯入另一個表,然後直接取代舊表

 我採用了以下的方式(較安全,雖然慢了一點) 
1.先將"未重複"的資料寫到另一個表 INSERT INTO `table_copy` SELECT * FROM `table` GROUP BY `field name` HAVING count(*)=1 
2.再將"重複"的資料寫到另一個表 INSERT INTO `table_copy` SELECT * FROM `table` GROUP BY `field name` HAVING count(*)>1 
3.直接用新表取代舊的表 

參考資料來源 
1、從MYSQL資料庫中找出重複的資料並刪除
2、[MYSQL]利用 SQL 找出欄位值重覆的記錄

2010年6月3日 星期四

postfix+mysql(auth)+postfixadmin at centos

之前一直找到在其他linux套件上的做法,一直做不成功
(要嘛是debian的,要嘛是ubuntu的,不然就是fedora的)

主要是postfix+dovecot來完成的
(還有一個是搭配courier-imap,但這個我一直做不起來..>.<)
此篇文章主要是參考這一篇
(http://www.campworld.net/thewiki/pmwiki.php/LinuxServersCentOS/Cent5VirtMailServer)

下面的內容僅從中摘錄部份重點

首先要準備的幾個軟件
1.postfix with mysql(這個可以參考http://www.pigo.idv.tw/archives/323)
(centos預設的postfix是不支援mysql的,務必參考上述文章重新安裝)
2.Dovecot
3.mysql
4.httpd
5.postfixadmin
(這個是網頁的程序,麻煩自己去抓回來放在你的web目錄下,之後透過web就可以管理郵件帳號)
6.cyrus-sasl,cyrus-sasl-lib,cyrus-sasl-devel,cyrus-sasl-sql,cyrus-sasl-plain
上面除了1,5之外,其他都可以用centos5.4內建的套件就好(yum install xxxx)

首先把postfixadmin設定好
新版的postfixadmin在安裝上做了一些改良,使用者只要先把資料庫及使用者建立起來
以及修改config.inc.php這個檔案,剩下的就全都可以在網頁上完成了(不必再自己手動建立資料表)
(config.inc.php裡面也都有針對各項參數做說明)
如同下面的步驟
Now we need to setup the mysql database for mysqladmin. We only need to create the database and user. The setup file will create the rest.
> mysql -u root -p -e "CREATE DATABASE postfix;"
> mysql -u root -p -e "CREATE USER postfix@localhost IDENTIFIED BY 'choose_a_password';"
> mysql -u root -p -e "GRANT ALL PRIVILEGES ON postfix . * TO postfix@localhost;"

Now its time to setup the config file. Don't forget to set your password. Find the following items and change them.
> cd /usr/share/postfixadmin
> nano -w config.inc.php


# 這一行要改成true,否則無法安裝
$CONF['configured'] = true;

// Postfix Admin Path
// Set the location to your Postfix Admin installation here.
$CONF['postfix_admin_url'] = '/mailadmin/';

// Database Config
// mysql = MySQL 3.23 and 4.0
// mysqli = MySQL 4.1
// pgsql = PostgreSQL
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';


$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['encrypt'] = 'cleartext';


接下來,換設定一下postfix的main.cf(/etc/postfix/main.cf)
關於postfix原本的一些設定我就不多談了
(如下這些)
# network settings
inet_interfaces = all
mydomain = yourdomain.com
myhostname = host.yourdomain.com
mynetworks = 192.168.0.0/16, 127.0.0.0/24,
mydestination = $myhostname, localhost.$mydomain, localhost
relay_domains = $mydestination
# mail delivery
recipient_delimiter = +
========================
上面這些設定用預設也行,要針對自己的情況修改也行
參考鳥哥的文章可以瞭解詳細內容(簡易 Mail Server 架設 -- Postfix 設定)
或是連到
HOWTO Virtual Mail Hosting on CentOS 5.x - Postfix MySQL Dovecot Postfix Admin
這篇原本的文章中,參考它文中所附上的完整main.cf及master.cf設定檔內容

本文只針對要利用mysql來管理所需增設的一些設定
在/etc/postfix/main.cf新增下述設定

# virtual setup
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_alias_maps.cf,
regexp:/etc/postfix/virtual_regexp
virtual_gid_maps = static:89 #your postfix gid
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual_mailbox_maps.cf
virtual_minimum_uid = 89
virtual_transport = virtual
virtual_uid_maps = static:89 #your postfix uid

# authentication
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes

# tls config
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.pem
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.pem
smtpd_tls_CAfile = /etc/postfix/ssl/smtpd.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

# rules restrictions
# smtpd_client_restrictions = reject_rbl_client zen.spamhaus.org
smtpd_helo_restrictions = permit_sasl_authenticated,
permit_mynetworks,
reject_non_fqdn_hostname
smtpd_sender_restrictions = reject_non_fqdn_sender,
reject_unknown_sender_domain
smtpd_recipient_restrictions = permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain
smtpd_helo_required = yes
unknown_local_recipient_reject_code = 550
disable_vrfy_command = yes
smtpd_data_restrictions = reject_unauth_pipelining


然後新增下面幾個個檔案
The postfix / mysql config files.

/etc/postfix/mysql-virtual_alias_maps.cf

hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = alias
select_field = goto
where_field = address


/etc/postfix/mysql-virtual_domains_maps.cf

hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'
這裡要注意一下,我在postfixadmin新增網域時,把"備份網域"勾起來了,造成我信件一直被主機退回
上面這一行sql語法,就是會造成找不到允許接收信件網域的原因
看是要把備份網域取消,或是修改這一行,把backupmx = '0' 拿掉都行


/etc/postfix/mysql-virtual_mailbox_maps.cf

hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = mailbox
select_field = maildir
where_field = username


接下來,修改這個檔案(讓smtp在寄信要求驗證時使用的設定檔)
/usr/lib/sasl2/smtpd.conf


pwcheck_method: auxprop
mech_list: PLAIN LOGIN
auxprop_plugin: sql
sql_verbose: yes
sql_engine: mysql
sql_hostnames: localhost
sql_user: postfix
sql_passwd: postfix
sql_database: postfix
sql_select: select password from mailbox where username = '%u@%r'


接下來,產生ssl的key讓postfix可以支援TLS

Now generate an SSL certificate for postfix to have TLS support.
> mkdir /etc/postfix/ssl
> cd /etc/postfix/ssl
> openssl req -new -x509 -nodes -out smtpd.pem -keyout smtpd.pem -days 3650

We need to touch a file. So type the follwoing.
> touch /etc/postfix/virtual_regexp
上面這個動作,就是在main.cf中
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_alias_maps.cf,
regexp:/etc/postfix/virtual_regexp
這一行要用到的檔案,讓你也可以手動編輯允許收信的電子郵件及網域
可以參考http://www.sympa.org/faq/postfix這篇文章
內文主要就是在講這檔案的用途

接下來是設定一下信件存放的目錄
Finally we'll configure the mail store directory. We put it in the /home directory to make backups and other item easy. So type the following.
> mkdir /home/vmail
> chmod 770 /home/vmail
> chown postfix:postfix /home/vmail

最後,修改dovecot的設定檔(/etc/dovecot.conf)

# Dovecot config file
auth default {
userdb sql {
args = /etc/dovecot-mysql.conf
}
passdb sql {
args = /etc/dovecot-mysql.conf
}
}
first_valid_uid = 89
default_mail_env = maildir:/home/vmail/%d/%n
protocols = imaps imap pop3s pop3
ssl_cert_file = /etc/postfix/ssl/smtpd.pem
ssl_key_file = /etc/postfix/ssl/smtpd.pem


新增/etc/dovecot-mysql.conf ,內容如下

driver = mysql
connect = host=localhost dbname=postfix user=postfix password=yourpassword
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 89 AS uid, 89 AS gid FROM mailbox WHERE username = '%u'


到這裡,整個作業就完成了,把postfix,dovecot都重新啟動後
這樣postfix就可以用postfixadmin來做管理了

文章只針對postfix,dovecot(pop3,imap)的部份做重點摘錄

之前一直找到在其他linux套件上的做法,一直做不成功
(要嘛是debian的,要嘛是ubuntu的,不然就是fedora的)

主要是postfix+dovecot來完成的
(還有一個是搭配courier-imap,但這個我一直做不起來..>.<)
此篇文章主要是參考這一篇
(http://www.campworld.net/thewiki/pmwiki.php/LinuxServersCentOS/Cent5VirtMailServer)

下面的內容僅從中摘錄部份重點

首先要準備的幾個軟件
1.postfix with mysql(這個可以參考http://www.pigo.idv.tw/archives/323)
(centos預設的postfix是不支援mysql的,務必參考上述文章重新安裝)
2.Dovecot
3.mysql
4.httpd
5.postfixadmin
(這個是網頁的程序,麻煩自己去抓回來放在你的web目錄下,之後透過web就可以管理郵件帳號)
6.cyrus-sasl,cyrus-sasl-lib,cyrus-sasl-devel,cyrus-sasl-sql,cyrus-sasl-plain
上面除了1,5之外,其他都可以用centos5.4內建的套件就好(yum install xxxx)

首先把postfixadmin設定好
新版的postfixadmin在安裝上做了一些改良,使用者只要先把資料庫及使用者建立起來
以及修改config.inc.php這個檔案,剩下的就全都可以在網頁上完成了(不必再自己手動建立資料表)
(config.inc.php裡面也都有針對各項參數做說明)
如同下面的步驟
Now we need to setup the mysql database for mysqladmin. We only need to create the database and user. The setup file will create the rest.
> mysql -u root -p -e "CREATE DATABASE postfix;"
> mysql -u root -p -e "CREATE USER postfix@localhost IDENTIFIED BY 'choose_a_password';"
> mysql -u root -p -e "GRANT ALL PRIVILEGES ON postfix . * TO postfix@localhost;"

Now its time to setup the config file. Don't forget to set your password. Find the following items and change them.
> cd /usr/share/postfixadmin
> nano -w config.inc.php


# 這一行要改成true,否則無法安裝
$CONF['configured'] = true;

// Postfix Admin Path
// Set the location to your Postfix Admin installation here.
$CONF['postfix_admin_url'] = '/mailadmin/';

// Database Config
// mysql = MySQL 3.23 and 4.0
// mysqli = MySQL 4.1
// pgsql = PostgreSQL
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';


$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['encrypt'] = 'cleartext';


接下來,換設定一下postfix的main.cf(/etc/postfix/main.cf)
關於postfix原本的一些設定我就不多談了
(如下這些)
# network settings
inet_interfaces = all
mydomain = yourdomain.com
myhostname = host.yourdomain.com
mynetworks = 192.168.0.0/16, 127.0.0.0/24,
mydestination = $myhostname, localhost.$mydomain, localhost
relay_domains = $mydestination
# mail delivery
recipient_delimiter = +
========================
上面這些設定用預設也行,要針對自己的情況修改也行
參考鳥哥的文章可以瞭解詳細內容(簡易 Mail Server 架設 -- Postfix 設定)
或是連到
HOWTO Virtual Mail Hosting on CentOS 5.x - Postfix MySQL Dovecot Postfix Admin
這篇原本的文章中,參考它文中所附上的完整main.cf及master.cf設定檔內容

本文只針對要利用mysql來管理所需增設的一些設定
在/etc/postfix/main.cf新增下述設定

# virtual setup
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_alias_maps.cf,
regexp:/etc/postfix/virtual_regexp
virtual_gid_maps = static:89 #your postfix gid
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual_mailbox_maps.cf
virtual_minimum_uid = 89
virtual_transport = virtual
virtual_uid_maps = static:89 #your postfix uid

# authentication
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes

# tls config
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.pem
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.pem
smtpd_tls_CAfile = /etc/postfix/ssl/smtpd.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

# rules restrictions
# smtpd_client_restrictions = reject_rbl_client zen.spamhaus.org
smtpd_helo_restrictions = permit_sasl_authenticated,
permit_mynetworks,
reject_non_fqdn_hostname
smtpd_sender_restrictions = reject_non_fqdn_sender,
reject_unknown_sender_domain
smtpd_recipient_restrictions = permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain
smtpd_helo_required = yes
unknown_local_recipient_reject_code = 550
disable_vrfy_command = yes
smtpd_data_restrictions = reject_unauth_pipelining


然後新增下面幾個個檔案
The postfix / mysql config files.

/etc/postfix/mysql-virtual_alias_maps.cf

hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = alias
select_field = goto
where_field = address


/etc/postfix/mysql-virtual_domains_maps.cf

hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'
這裡要注意一下,我在postfixadmin新增網域時,把"備份網域"勾起來了,造成我信件一直被主機退回
上面這一行sql語法,就是會造成找不到允許接收信件網域的原因
看是要把備份網域取消,或是修改這一行,把backupmx = '0' 拿掉都行


/etc/postfix/mysql-virtual_mailbox_maps.cf

hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = mailbox
select_field = maildir
where_field = username


接下來,修改這個檔案(讓smtp在寄信要求驗證時使用的設定檔)
/usr/lib/sasl2/smtpd.conf


pwcheck_method: auxprop
mech_list: PLAIN LOGIN
auxprop_plugin: sql
sql_verbose: yes
sql_engine: mysql
sql_hostnames: localhost
sql_user: postfix
sql_passwd: postfix
sql_database: postfix
sql_select: select password from mailbox where username = '%u@%r'


接下來,產生ssl的key讓postfix可以支援TLS

Now generate an SSL certificate for postfix to have TLS support.
> mkdir /etc/postfix/ssl
> cd /etc/postfix/ssl
> openssl req -new -x509 -nodes -out smtpd.pem -keyout smtpd.pem -days 3650

We need to touch a file. So type the follwoing.
> touch /etc/postfix/virtual_regexp
上面這個動作,就是在main.cf中
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_alias_maps.cf,
regexp:/etc/postfix/virtual_regexp
這一行要用到的檔案,讓你也可以手動編輯允許收信的電子郵件及網域
可以參考http://www.sympa.org/faq/postfix這篇文章
內文主要就是在講這檔案的用途

接下來是設定一下信件存放的目錄
Finally we'll configure the mail store directory. We put it in the /home directory to make backups and other item easy. So type the following.
> mkdir /home/vmail
> chmod 770 /home/vmail
> chown postfix:postfix /home/vmail

最後,修改dovecot的設定檔(/etc/dovecot.conf)

# Dovecot config file
auth default {
userdb sql {
args = /etc/dovecot-mysql.conf
}
passdb sql {
args = /etc/dovecot-mysql.conf
}
}
first_valid_uid = 89
default_mail_env = maildir:/home/vmail/%d/%n
protocols = imaps imap pop3s pop3
ssl_cert_file = /etc/postfix/ssl/smtpd.pem
ssl_key_file = /etc/postfix/ssl/smtpd.pem


新增/etc/dovecot-mysql.conf ,內容如下

driver = mysql
connect = host=localhost dbname=postfix user=postfix password=yourpassword
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 89 AS uid, 89 AS gid FROM mailbox WHERE username = '%u'


到這裡,整個作業就完成了,把postfix,dovecot都重新啟動後
這樣postfix就可以用postfixadmin來做管理了

文章只針對postfix,dovecot(pop3,imap)的部份做重點摘錄

2010年4月30日 星期五

mysql匯入/匯出

備份及匯入 mysql database
備份 SQL data:
>mysqldump -u 使用者名稱 -p –default-character-set=utf8 資料庫名稱 > backup.sql

匯入 SQL data:
>mysql -u 使用者名稱 -p 資料庫名稱 < backup.sql 備份及匯入 mysql database
備份 SQL data:
>mysqldump -u 使用者名稱 -p –default-character-set=utf8 資料庫名稱 > backup.sql

匯入 SQL data:
>mysql -u 使用者名稱 -p 資料庫名稱 < backup.sql

2009年5月5日 星期二

pure-ftpd + mysql + web_manage

之前己經建置過了,但沒仔細記錄
這次就好好的記錄起來吧~~
參考了很多地方...但總是有缺了一些狀況的說明...
首先先去下載二個檔案
1.pure-ftpd-1.0.22.tar.gz
2.pure-ftpd_user_manage-2.1.tar.tgz

然後就是一連串的安裝過程了...


首先安裝 pure-ftpd-1.0.22.tar.gz
解開後,到目錄下執行
./configure \
--prefix=/usr/local/pureftpd \
--with-mysql \
--with-paranoidmsg \
--with-shadow \
--with-welcomemsg \
--with-uploadscript \
--with-quotas \
--with-cookie \
--with-virtualhosts \
--with-virtualchroot \
--with-diraliases \
--with-sysquotas \
--with-ratios \
--with-ftpwho \
--with-throttling

#make
#make install
#cd configuration-file
#chmod u+x pure-config.pl
#cp pure-config.pl /usr/local/pureftpd/sbin/
#cp pure-ftpd.conf /etc/pureftpd/

到這裡算是做好pure-ftpd的準備工作
======================================================================
若遇到
configure: error: libmysqlclient is needed for MySQL support

則先安裝mysql-devel,即可解決這問題
(yum install mysql-devel)
以及
將/usr/lib64/mysql/内的libmysqlclient.so.15.0.0做個軟連結到/usr/lib下即可
PHP預設是去的 /usr/lib/搜尋的,所以會找不到

上面的資訊來自: E点废墟(www.xok.la) 详细出处参考:http://xok.la/2008/08/configure_error_cannot_find_libmysqlclient_under.html

======================================================================
接下來安裝 pure-ftpd_user_manage-2.1.tar.tgz
解開它
tar -xvzf pure-ftpd_user_manage-2.1.tar.tgz
然後從網頁去做設定
http://xxxxxxx/pure-ftpd_user_manage/install.php
照著它的步驟一步一步設定好

然後將它最後產生的pureftpd-mysql設定檔複製起來
將它存到 /etc/pureftpd/pureftpd-mysql.conf
(記得將install.php刪除)
接下來修改
/etc/pureftpd/pure-ftpd.conf

# MySQL configuration file (see README.MySQL)
MySQLConfigFile /etc/pureftpd/pureftpd-mysql.conf

# Minimum UID for an authenticated user to log in.
MinUID 100
------->這個要注意一下,利用mysql設定帳號時,選登入的身份時
所選的UID記得要比這個數字高才可以登入

======================================================================
然後...就是執行程式了
依照剛才拷貝的pure-config.pl以及pure-ftpd.conf的路徑
/usr/local/pureftpd/sbin/pure-config.pl /etc/pureftpd/pure-ftpd.conf
這樣即可順利開啟起來

之前己經建置過了,但沒仔細記錄
這次就好好的記錄起來吧~~
參考了很多地方...但總是有缺了一些狀況的說明...
首先先去下載二個檔案
1.pure-ftpd-1.0.22.tar.gz
2.pure-ftpd_user_manage-2.1.tar.tgz

然後就是一連串的安裝過程了...


首先安裝 pure-ftpd-1.0.22.tar.gz
解開後,到目錄下執行
./configure \
--prefix=/usr/local/pureftpd \
--with-mysql \
--with-paranoidmsg \
--with-shadow \
--with-welcomemsg \
--with-uploadscript \
--with-quotas \
--with-cookie \
--with-virtualhosts \
--with-virtualchroot \
--with-diraliases \
--with-sysquotas \
--with-ratios \
--with-ftpwho \
--with-throttling

#make
#make install
#cd configuration-file
#chmod u+x pure-config.pl
#cp pure-config.pl /usr/local/pureftpd/sbin/
#cp pure-ftpd.conf /etc/pureftpd/

到這裡算是做好pure-ftpd的準備工作
======================================================================
若遇到
configure: error: libmysqlclient is needed for MySQL support

則先安裝mysql-devel,即可解決這問題
(yum install mysql-devel)
以及
將/usr/lib64/mysql/内的libmysqlclient.so.15.0.0做個軟連結到/usr/lib下即可
PHP預設是去的 /usr/lib/搜尋的,所以會找不到

上面的資訊來自: E点废墟(www.xok.la) 详细出处参考:http://xok.la/2008/08/configure_error_cannot_find_libmysqlclient_under.html

======================================================================
接下來安裝 pure-ftpd_user_manage-2.1.tar.tgz
解開它
tar -xvzf pure-ftpd_user_manage-2.1.tar.tgz
然後從網頁去做設定
http://xxxxxxx/pure-ftpd_user_manage/install.php
照著它的步驟一步一步設定好

然後將它最後產生的pureftpd-mysql設定檔複製起來
將它存到 /etc/pureftpd/pureftpd-mysql.conf
(記得將install.php刪除)
接下來修改
/etc/pureftpd/pure-ftpd.conf

# MySQL configuration file (see README.MySQL)
MySQLConfigFile /etc/pureftpd/pureftpd-mysql.conf

# Minimum UID for an authenticated user to log in.
MinUID 100
------->這個要注意一下,利用mysql設定帳號時,選登入的身份時
所選的UID記得要比這個數字高才可以登入

======================================================================
然後...就是執行程式了
依照剛才拷貝的pure-config.pl以及pure-ftpd.conf的路徑
/usr/local/pureftpd/sbin/pure-config.pl /etc/pureftpd/pure-ftpd.conf
這樣即可順利開啟起來

2008年2月29日 星期五

用PHP函數解決SQL injection

轉錄自
用PHP函数解决SQL injection

SQL injection問題在ASP上可是鬧得沸沸揚揚當然還有不少國內外著名的PHP程式“遇難”。
如果你網站空間的php.ini文件的magic_quotes_gpc設成了off,
那麽PHP就不會自動在敏感字元前加上反斜符號(\),由於表單提交的內容可能含有敏感字元,
如單引號('),就導致了SQL injection的漏洞。
在這種情況下,我們可以用addslashes()來解決問題,它會自動在敏感字元前添加反斜符號。
但是,上面的方法只適用於magic_quotes_gpc=Off的情況。
作爲一個開發者,你不知道每個用戶的magic_quotes_gpc是On還是Off,
如果把全部的資料都用上addslashes(),那不是“濫殺無辜”了?
假如magic_quotes_gpc=On,並且又用了addslashes()函數,那讓我們來看看:


//如果從表單提交一個變數$_POST['message'],內容爲 Tom's book
//這此加入連接MySQL資料庫的代碼,自己寫吧
//在$_POST['message']的敏感字元前加上反斜杠
$_POST['message'] = addslashes($_POST['message']);

//由於magic_quotes_gpc=On,所以又一次在敏感字元前加反斜杠
$sql = "INSERT INTO msg_table VALUE('$_POST[message]');";

//發送請求,把內容保存到資料庫內
$query = mysql_query($sql);

//如果你再從資料庫內提取這個記錄並輸出,就會看到 Tom\'s book
?>

這樣的話,在magic_quotes_gpc=On的環境,所有輸入的單引號(')都會變成(\')……
其實我們可以用get_magic_quotes_gpc()函數輕易地解決這個問題。
當magic_quotes_gpc=On時,該函數返回TRUE;當magic_quotes_gpc=Off時,返回FALSE。
至此,肯定已經有不少人意識到:問題已經解決。請看

//如果magic_quotes_gpc=Off,那就爲提單提交的$_POST['message']的敏感字元加反斜杠
//magic_quotes_gpc=On的情況下,則不加
if (!get_magic_quotes_gpc()) {
$_POST['message'] = addslashes($_POST['message']);
} else {}
?>

其實說到這,問題已經解決。下面再說一個小技巧。
有時表單提交的變數不止一個,可能有十幾個,幾十個。
那麽一次一次地複製/粘帖addslashes(),是否麻煩了一點?
由於從表單或URL獲取的資料都是以陣列形式出現的,如$_POST、$_GET
那就自定義一個可以“橫掃千軍”的函數:

function quotes($content)
{
//如果magic_quotes_gpc=Off,那麽就開始處理
if (!get_magic_quotes_gpc()) {
//判斷$content是否爲陣列
if (is_array($content)) {
//如果$content是陣列,那麽就處理它的每一個單無
foreach ($content as $key=>$value) {
$content[$key] = addslashes($value);
}
} else {
//如果$content不是陣列,那麽就僅處理一次
addslashes($content);
}
} else {
//如果magic_quotes_gpc=On,那麽就不處理
}
//返回$content
return $content;
}
?>



轉錄自
用PHP函数解决SQL injection

SQL injection問題在ASP上可是鬧得沸沸揚揚當然還有不少國內外著名的PHP程式“遇難”。
如果你網站空間的php.ini文件的magic_quotes_gpc設成了off,
那麽PHP就不會自動在敏感字元前加上反斜符號(\),由於表單提交的內容可能含有敏感字元,
如單引號('),就導致了SQL injection的漏洞。
在這種情況下,我們可以用addslashes()來解決問題,它會自動在敏感字元前添加反斜符號。
但是,上面的方法只適用於magic_quotes_gpc=Off的情況。
作爲一個開發者,你不知道每個用戶的magic_quotes_gpc是On還是Off,
如果把全部的資料都用上addslashes(),那不是“濫殺無辜”了?
假如magic_quotes_gpc=On,並且又用了addslashes()函數,那讓我們來看看:


//如果從表單提交一個變數$_POST['message'],內容爲 Tom's book
//這此加入連接MySQL資料庫的代碼,自己寫吧
//在$_POST['message']的敏感字元前加上反斜杠
$_POST['message'] = addslashes($_POST['message']);

//由於magic_quotes_gpc=On,所以又一次在敏感字元前加反斜杠
$sql = "INSERT INTO msg_table VALUE('$_POST[message]');";

//發送請求,把內容保存到資料庫內
$query = mysql_query($sql);

//如果你再從資料庫內提取這個記錄並輸出,就會看到 Tom\'s book
?>

這樣的話,在magic_quotes_gpc=On的環境,所有輸入的單引號(')都會變成(\')……
其實我們可以用get_magic_quotes_gpc()函數輕易地解決這個問題。
當magic_quotes_gpc=On時,該函數返回TRUE;當magic_quotes_gpc=Off時,返回FALSE。
至此,肯定已經有不少人意識到:問題已經解決。請看

//如果magic_quotes_gpc=Off,那就爲提單提交的$_POST['message']的敏感字元加反斜杠
//magic_quotes_gpc=On的情況下,則不加
if (!get_magic_quotes_gpc()) {
$_POST['message'] = addslashes($_POST['message']);
} else {}
?>

其實說到這,問題已經解決。下面再說一個小技巧。
有時表單提交的變數不止一個,可能有十幾個,幾十個。
那麽一次一次地複製/粘帖addslashes(),是否麻煩了一點?
由於從表單或URL獲取的資料都是以陣列形式出現的,如$_POST、$_GET
那就自定義一個可以“橫掃千軍”的函數:

function quotes($content)
{
//如果magic_quotes_gpc=Off,那麽就開始處理
if (!get_magic_quotes_gpc()) {
//判斷$content是否爲陣列
if (is_array($content)) {
//如果$content是陣列,那麽就處理它的每一個單無
foreach ($content as $key=>$value) {
$content[$key] = addslashes($value);
}
} else {
//如果$content不是陣列,那麽就僅處理一次
addslashes($content);
}
} else {
//如果magic_quotes_gpc=On,那麽就不處理
}
//返回$content
return $content;
}
?>



2007年9月3日 星期一

unix-like底下 apache2+php5+mysql5安裝方式

節錄自[分享] unix-like底下 apache2+php5+mysql5安裝方式
感謝acman's 便利地毯的分享

紅字部份為輸入之指令
切換目錄至/usr/local/src ;準備自行編譯
cd /usr/local/src

到以下的官方網站下載需要的版本
MySQL官方網站:http://www.mysql.com
Apache官方網站:http://www.apache.org
PHP官方網站:http://www.php.net

安裝mysqld:mysql-5.0.37
解開tarball
tar -zxvf mysql-5.0.37.tar.gz
切換到解開的目錄下
cd mysql-5.0.37
1.組態:(編譯參數參考原廠doc或是google找其它人的經驗或是依之前經驗)
./configure --prefix=/usr/local/mysql --localstatedir=/home/mysql --with-mysqld-user=mysql --enable-large-files
2.編譯
make
3.安裝
make install
4.複製系統設定檔至指定位置:
cp support-files/my-medium.cnf /etc/my.cnf
5.增加mysqld要使用的user跟group
vi /etc/group
新增一行內容為:mysql:x:60:
vi /etc/passwd
新增一行內容為:mysql:x:60:60:mysql:/home/mysql:/bin/false
6.切換資料夾
cd /usr/local/mysql
7.安裝系統資料庫
bin/mysql_install_db --user=mysql
8.更改目錄權限
chown -R root:mysql /home/mysql
9.啟動 MySql Server
bin/mysqld_safe --user=mysql &
10.更改資料庫管理者的管理密碼("new-password"部分請自行輸入):
bin/mysqladmin -u root password new-password

安裝apache:httpd-2.2.4
切換目錄
cd /usr/local/src
解開tarball
tar -zxvf httpd-2.2.4.tar.gz
切換到解開的目錄下
cd httpd-2.2.4
1.組態:
./configure --prefix=/home/apache --enable-shared=max --enable-module=most --enable-so
祝註:因為我偷懶的原因,所以apache的module是直接掛載,不在httpd.conf中一個一個自行選定是否載入
有空再做自行選擇的部份
2.編譯:
make
3.安裝:
make install

安裝php:php-5.2.1
安裝php前:為讓php support更多模組,以下部份先安裝(常用的)
指令:
gentoo適用:
emerge zlib
emerge libpng
emerge freetype
emerge jpeg
emerge gd
emerge libxml2

自行編譯者:自行找到tarball後(問google),直接組態->編譯->安裝,無需加任何參數
安裝php:php-5.2.1
切換目錄
cd /usr/local/src
解開tarball
tar -jxvf php-5.2.1.tar.bz2
切換到解開的目錄下
cd php-5.2.1

1.組態:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.2.4/bin/apxs --with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql --with-gd --with-jpeg --with-zlib --with-libxml --enable-socket --with-iconv --with-pear --enable-zend-multibyte
這部份同apache,php可以把許多功能都編成extensions,僅載入需要的部份,這也是我偏愛的方式.....不過在這邊也偷懶
2.編譯
make
3.安裝
make install
4. 檢查是否有生成apache需要的php module
ls -al /usr/local/apache2.2.4/modules/libphp5.so
5. 複制php的設定檔
cp /usr/local/src/php-5.2.1/php.ini-dist /usr/local/php/

設定apache的httpd.conf
1. 查看是否有增加這一行
LoadModule php5_module modules/libphp5.so
2.更改admin信箱:
ServerAdmin 你的emailaddress
3.設定伺服器名稱(可以使用dmian:www.ooo.net:80 或 192.168.1.1:80)
ServerName 192.168.1.1:80(用你自己機器的ip address啊)
4.找到DirectoryIndex敘述,設定首頁名稱加上 index.php
DirectoryIndex index.htm index.html index.php
5.找到AddType部份,增加一行:
AddType application/x-httpd-php .php
6.啟動apache
/usr/local/apache2.2.4/bin/apachectl start
7.檢查php是否有正常運作
在/usr/local/apache2.2.4/htdocs/底下新增一個檔案:info.php,內容如下:
<?
phpinfo();
?>

8.用瀏覽器看 http://你的ip/info.php
有phpinfo畫面生成的話就ok啦 節錄自[分享] unix-like底下 apache2+php5+mysql5安裝方式
感謝acman's 便利地毯的分享

紅字部份為輸入之指令
切換目錄至/usr/local/src ;準備自行編譯
cd /usr/local/src

到以下的官方網站下載需要的版本
MySQL官方網站:http://www.mysql.com
Apache官方網站:http://www.apache.org
PHP官方網站:http://www.php.net

安裝mysqld:mysql-5.0.37
解開tarball
tar -zxvf mysql-5.0.37.tar.gz
切換到解開的目錄下
cd mysql-5.0.37
1.組態:(編譯參數參考原廠doc或是google找其它人的經驗或是依之前經驗)
./configure --prefix=/usr/local/mysql --localstatedir=/home/mysql --with-mysqld-user=mysql --enable-large-files
2.編譯
make
3.安裝
make install
4.複製系統設定檔至指定位置:
cp support-files/my-medium.cnf /etc/my.cnf
5.增加mysqld要使用的user跟group
vi /etc/group
新增一行內容為:mysql:x:60:
vi /etc/passwd
新增一行內容為:mysql:x:60:60:mysql:/home/mysql:/bin/false
6.切換資料夾
cd /usr/local/mysql
7.安裝系統資料庫
bin/mysql_install_db --user=mysql
8.更改目錄權限
chown -R root:mysql /home/mysql
9.啟動 MySql Server
bin/mysqld_safe --user=mysql &
10.更改資料庫管理者的管理密碼("new-password"部分請自行輸入):
bin/mysqladmin -u root password new-password

安裝apache:httpd-2.2.4
切換目錄
cd /usr/local/src
解開tarball
tar -zxvf httpd-2.2.4.tar.gz
切換到解開的目錄下
cd httpd-2.2.4
1.組態:
./configure --prefix=/home/apache --enable-shared=max --enable-module=most --enable-so
祝註:因為我偷懶的原因,所以apache的module是直接掛載,不在httpd.conf中一個一個自行選定是否載入
有空再做自行選擇的部份
2.編譯:
make
3.安裝:
make install

安裝php:php-5.2.1
安裝php前:為讓php support更多模組,以下部份先安裝(常用的)
指令:
gentoo適用:
emerge zlib
emerge libpng
emerge freetype
emerge jpeg
emerge gd
emerge libxml2

自行編譯者:自行找到tarball後(問google),直接組態->編譯->安裝,無需加任何參數
安裝php:php-5.2.1
切換目錄
cd /usr/local/src
解開tarball
tar -jxvf php-5.2.1.tar.bz2
切換到解開的目錄下
cd php-5.2.1

1.組態:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.2.4/bin/apxs --with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql --with-gd --with-jpeg --with-zlib --with-libxml --enable-socket --with-iconv --with-pear --enable-zend-multibyte
這部份同apache,php可以把許多功能都編成extensions,僅載入需要的部份,這也是我偏愛的方式.....不過在這邊也偷懶
2.編譯
make
3.安裝
make install
4. 檢查是否有生成apache需要的php module
ls -al /usr/local/apache2.2.4/modules/libphp5.so
5. 複制php的設定檔
cp /usr/local/src/php-5.2.1/php.ini-dist /usr/local/php/

設定apache的httpd.conf
1. 查看是否有增加這一行
LoadModule php5_module modules/libphp5.so
2.更改admin信箱:
ServerAdmin 你的emailaddress
3.設定伺服器名稱(可以使用dmian:www.ooo.net:80 或 192.168.1.1:80)
ServerName 192.168.1.1:80(用你自己機器的ip address啊)
4.找到DirectoryIndex敘述,設定首頁名稱加上 index.php
DirectoryIndex index.htm index.html index.php
5.找到AddType部份,增加一行:
AddType application/x-httpd-php .php
6.啟動apache
/usr/local/apache2.2.4/bin/apachectl start
7.檢查php是否有正常運作
在/usr/local/apache2.2.4/htdocs/底下新增一個檔案:info.php,內容如下:
<?
phpinfo();
?>

8.用瀏覽器看 http://你的ip/info.php
有phpinfo畫面生成的話就ok啦

2007年4月14日 星期六

MySQL 資料型態

常會搜尋到,就記錄起來吧~

資料來源:《MySQL資料型態》

一.資料型態
二.數值
三.日期時間
常會搜尋到,就記錄起來吧~

資料來源:《MySQL資料型態》

一.資料型態
二.數值
三.日期時間