Issue with installing the mysql gem: solved, how to install mysql gem without issue

When tried to install mysql gem I got following error
[root@localhost siwan]# sudo gem install mysql
Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for mysql_ssl_set()… yes
checking for rb_str_set_len()… no
checking for rb_thread_start_timer()… yes
checking for mysql.h… no
checking for mysql/mysql.h… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/usr/bin/ruby
–with-mysql-config
–without-mysql-config

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

To find the mysql path on machine used following command
[root@localhost siwan]# which mysql
/usr/bin/mysql

I tried following command:
[root@localhost siwan]# sudo gem install mysql — –with-mysql-dir=/usr/bin/mysql

I Got the same error

[root@localhost siwan]# sudo gem install mysql — –with-mysql-dir=/usr/bin/mysql
Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for mysql_ssl_set()… yes
checking for rb_str_set_len()… no
checking for rb_thread_start_timer()… yes
checking for mysql.h… no
checking for mysql/mysql.h… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/usr/bin/ruby
–with-mysql-config
–without-mysql-config

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
ERROR: could not find gem — locally or in a repository
ERROR: could not find gem –with-mysql-dir=/usr/bin/mysql locally or in a repository

Then I checked the mysql-devel
[root@localhost siwan]# yum list mysql-devel
Loaded plugins: refresh-packagekit
Available Packages
mysql-devel.i586 5.1.37-1.fc11 updates

Then I Installed the mysql-devel
[root@localhost siwan]# yum install mysql-devel
Installed:
mysql-devel.i586 0:5.1.37-1.fc11
Complete!

Then I tried the mysql Gem installing…..I am able to install the mysql gem…
[root@localhost siwan]# gem install mysql
Building native extensions. This could take a while…
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1…
Installing RDoc documentation for mysql-2.8.1…
[root@localhost siwan]#

How to setup mongrel cluster setup on fedora

First install the following gems:
#su
#gem install mongrel
#gem install mongrel_cluster
#cd project_name
#mongrel_rails cluster::configure -e production -p 3000 -N 3 -c /home/siwan/project_name -a 127.0.0.1 —-prefix /project_name
# mongrel_rails cluster::start

You are able to start your applicaton at http://127.0.0.1:3000, http://127.0.0.1:3001 and http://127.0.0.1:3002

for all the cluster
# mongrel_rails cluster::stop

Advanced prepairation for production realeaze
$ mkdir /etc/mongrel_cluster

#vim /etc/mongrel_cluster/project_name.yml
copy and paste following text;
user: project_name
cwd: //home/siwan/project_name
log_file: /home/siwan/project_name/mongrel.log
port: “3000”
environment: production
group: dev
address: localhost
pid_file: /home/siwan/project_name/tmp/pids/mongrel.pid
servers: 3

or you can run the following command

or copy and paste the content from config/mongrel_cluster.yml file to /etc/mongrel_cluster/project_name.yml

# ln -s /home/siwan/project_name/config/mongrel_cluster.yml /etc/mongrel_cluster/project_name.yml

Then open your httpd.conf file for apache configration:

<Proxy balancer://project_name>
BalancerMember http://127.0.0.1:3000
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>

<VirtualHost *:80>
ProxyPreserveHost On
# Avoid open you server to proxying
ProxyRequests Off
# Options +FollowSymLinks
RewriteEngine On

RewriteRule ^/(images|stylesheet|javascript|html)/?(.*) /home/siwan/project_name/public/$0 [L]
ServerAdmin siwan@yahoo.co.in
DocumentRoot /home/project_name/
ServerName example.com
RewriteRule  ^/(.*)$  balancer://project_name%{REQUEST_URI} [P,QSA,L]
</VirtualHost>

Restart the apache server
#/etc/init.d/httpd restart

Command for restart the mongrel servers from any where
# mongrel_rails cluster::restart -C /etc/mongrel_cluster/project_name.yml

How to install mysql-connector-java / mysql-connector-odbc on fedora

I am using the Fedora9 for installation
I downloaded rmp file from this location.
http://rpm.pbone.net/index.php3/stat/4/idpl/7221422/com/mysql-connector-java-3.1.12-5.fc9.i386.rpm.html

If you are using the fedora 10 or 11, you can use this url;
http://www.rpmfind.net/linux/rpm2html/search.php?query=mysql-connector-java&submit=Search+…&system=fedora+9&arch=

[siwan@localhost ]$ su
Password:
[root@localhost ]# rpm -Uvh mysql-connector-java-3.1.12-5.fc9.i386.rpm
Preparing… ########################################### [100%]
1:mysql-connector-java ########################################### [100%]
[root@localhost ]#

how to install mysql-connector-odbc on fedora

I downloaded rmp file from this location.
http://rpm.pbone.net/index.php3?stat=3&search=mysql-connector-odbc&srodzaj=3

[root@localhost Desktop]# rpm -Uvh mysql-connector-odbc-3.51.24r1071-1.fc9.i386.rpm
Preparing… ########################################### [100%]
1:mysql-connector-odbc ########################################### [100%]
[root@localhost Desktop]#

How to find Mysql database engine type

Mysql tutorial, How to find Mysql database engine type.  You need to use this command for checking the engine type. command for checking engine type.

How to find Mysql database engine type

SHOW TABLE STATUS WHERE Name = ‘users’;

Or Use this command for checking the all table’s engine type.

SHOW TABLE STATUS;

Or You can use this command for database:

mysqlshow –status db_name;

I used following URL for creating this commands:

http://dev.mysql.com/doc/refman/4.1/en/show-table-status.html

php create xml file from mysql

php create xml file from mysql, Here I am giving you the very basic sample code for creating XML file through PHP and MYsql. We given code sample for this.

php create xml file from mysql

<?php

// We'll be outputting a PDF
header('Content-type: text/xml');

echo ""

$db_name = "testDB";
$connection = mysql_connect("example.com", "username", "password") or die("Could not connect.");
$table_name = 'user';

$query = "select * from " . $table_name;

$result = mysql_query($query, $connection) or die("Could not complete database query");
$num = mysql_num_rows($result);

while ($row = mysql_fetch_assoc($result)) {
echo "". $row['firstname']."";
echo "". $row['lastname']."";
echo "
". $row['address']."

";
echo "". $row['age']."";
}

?>

Solved :Error establishing a database connection

Many times I saw this message. “Error establishing a database connection”. That time I did not understand why this message is coming.

When started working on WordPress blog Plugins, Themes. Then I got to know about this error.
Whenever you mis-configured the wp-config.php file. You will this kind of error.

You need to Fill following information correctly:(dont forget to create database your own)
** The name of the database for WordPress */

define(‘DB_NAME’, ‘wordpress’);

/** MySQL database username */

define(‘DB_USER’, ‘root’);

/** MySQL database password */

define(‘DB_PASSWORD’, ”);

/** MySQL hostname */

define(‘DB_HOST’, ‘localhost’);

This will solve your problem.

Php Mysql Question and Answers for Interview

What is the difference between PHP4 and PHP5?
PHP4 cannot support oops concepts and Zend engine 1 is used.
PHP5 supports oops concepts and Zend engine 2 is used.
Error supporting is increased in PHP5.
XML and SQLLite will is increased in PHP5.Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?
Yes we can include that many times we want, but here are some things to make sure of:
(including abc.PHP, the file names are case-sensitive)
there shouldn’t be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php

How i can get ip address – REMOTE_ADDR – the IP address of the client
REMOTE_HOST – the host address of the client, if available

What is the difference between echo and print statement? – echo() can take multiple expressions,Print cannot take multiple expressions.
echo has the slight performance advantage because it doesn’t have a return value.
True, echo is a little bit faster.

How we know browser properties -echo $_SERVER[‘HTTP_USER_AGENT’] . “<hr /> “;
$browser = get_browser();
foreach ($browser as $name => $value) {
echo “<b>$name</b> $value <br /> “;
}

How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)

What is difference between require_once(), require(), include(). Becouse above three function usely use to call a file in another file.
Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).
So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don’t include the file more times and you will not get the “function re-declared” error.
Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING.
There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().

How do I generate a random number from-php?
srand((double)microtime()*1000000);
echo rand(0,100);

How do I set the browser timeout?
set_time_limit(900);
this sets the timeout too 900 seconds / 15 minutes.

How can I do error handling in php?

Is it possible to connect to a ftp server with php?
Yes it is possible, you can use the ftp_connect function. (PHP 3>= 3.0.13, PHP 4 >= 4.0b4)

How do I find out how a user came to my page?
You have the variable $HTTP_REFERER which holds the page that refered to you page, if there are any referer, ie if the user enters your url directly the referer variable will be empty.

How can I add text to an image?
array imagettftext ( resource $image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text )
how to rotate an image using php code?
$move90 = imagerotate($myimage,90);
//$myimage is the reference to the loaded image, eg through imagecreatefromjpeg

How do I find the size of an array? –use Count function
$values = range(“A”,”Z”);
echo count($values);

How do I remove escape characters from data?
$data = “I\’m the king of the castle”;
echo stripslashes($data); //I’m the king of the castle

What are magic quotes?
Magic quotes is a configuration setting within PHP that means that all data containing a single or double quote, or NUL, will automatically be escaped with a backslash before being entered into a database.

How can we encrypt the username and password using PHP?

What is the difference between $message and $$message?
$message is a simple variable whereas $$message is a reference variable.

What are the differences between DROP a table and TRUNCATE a table?

What’s the difference between md5(), crc32() and sha1() crypto on PHP?
The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

How to set cookies?
setcookie(’variable’,’value’,’time’)
;

Important mysql queries

I written article for my personal purpose. I am using some mysql query on daily. I created the list of my Important mysql queries.

Important mysql queries

Taking backup of all mysql databases

>mysqldump -uroot -p --all-databases >> all_database_dump.sql;

for single database

mysqldump -uroot -p public_wordpressmu wp_1_posts > one.sql

database import from sql file

mysql –verbose -uroot -p public_wordpressmu wp_1_posts < one.sql

Creating Trigger

create trigger
DROP TRIGGER wordpress.after_wp_1_post_update;

delimiter //

CREATE TRIGGER wordpressmu.after_wp_1_post_update

AFTER UPDATE ON wordpressmu.wp_1_posts

FOR EACH ROW

IF new.post_status = ‘publish’ THEN

INSERT INTO .article_posts (id,ref_id, title, status,
comments_on, created_at, updated_at) values (new.id,new.id,
new.post_title, new.post_status, 1, new.post_date, new.post_date);

END IF;

//

delimiter ;

Insert from different table (migration)

INSERT INTO database_anme.TableName(id, ref_id, title, status, comments_on, created_at, updated_at) select id, id, post_title, post_status, 1, post_date,post_date from wordpress.wp_1_posts

Update multiple rows in through Sql query

Update user set status=”ok” where id in (2 ,3 ,4 ,5,6)

changing all post path and image path
UPDATE wp_1_posts SET post_content = REPLACE(post_content, ‘test.siwan.com’, ‘www.siwan.com’);

WordPress -fetching category through sql queryfrom post

SELECT wp_1_term_taxonomy.taxonomy, wp_1_term_relationships.object_id, wp_1_terms.name, wp_1_posts.post_title
FROM wp_1_posts INNER JOIN ((wp_1_terms INNER JOIN wp_1_term_taxonomy ON wp_1_terms.term_id = wp_1_term_taxonomy.term_id) INNER JOIN wp_1_term_relationships ON wp_1_term_taxonomy.term_taxonomy_id = wp_1_term_relationships.term_taxonomy_id) ON wp_1_posts.ID = wp_1_term_relationships.object_id
WHERE wp_1_term_taxonomy.taxonomy=’category’ and wp_1_term_relationships.object_id=’217′
ORDER BY wp_1_term_relationships.object_id ;

CREATE DATABASE DB-NAME;
CREATE USER ‘DB-NAME’@’localhost’ IDENTIFIED BY ‘DB-NAME@123’;
grant all on USER-NAME.* to ‘DB-NAME’@’%’ identified by ‘DB-NAME@123’;
grant all on USER-NAME.* to ‘DB-NAME’@’localhost’ identified by ‘DB-NAME@123’;
FLUSH PRIVILEGES;

Getting Information about Databases and Tables

MySQL provides a SHOW statement that has several variant forms that display information about databases and the tables in them. SHOW is helpful for keeping track of the contents of your databases and for reminding yourself about the structure of your tables. You can also use SHOW prior to issuing ALTER TABLE; it’s often easier to figure out how to specify a change to a column after you determine the column’s current definition.

The SHOW statement can be used to obtain information about several aspects of your databases and tables:

  • List the databases managed by the server:
    SHOW DATABASES;
  • List the tables in the current database or in a given database:
    SHOW TABLES;
    SHOW TABLES FROM db_name;
  • Note that SHOW TABLES doesn’t show TEMPORARY tables.
  • Display information about columns or indexes in a table:
    SHOW COLUMNS FROM tbl_name;
    SHOW INDEX FROM tbl_name;
  • The DESCRIBE tbl_name and EXPLAIN tbl_name statements are synonymous with SHOW COLUMNS FROM tbl_name.
  • Display descriptive information about tables in the current database or in a given database:
    SHOW TABLE STATUS;
    SHOW TABLE STATUS FROM db_name;
  • This statement was introduced in MySQL 3.23.0.
  • Display the CREATE TABLE statement that corresponds to the current structure of a table:
    SHOW CREATE TABLE tbl_name;
  • This statement was introduced in MySQL 3.23.20.

Several forms of SHOW take a LIKE 'pat' clause allowing a pattern to be given that limits the scope of the output. 'pat' is interpreted as a SQL pattern that can include the ‘%‘ and ‘_‘ wildcard characters. For example, the following statement displays the names of tables in the current database that begin with 'geo':

SHOW TABLES LIKE 'geo%';

To match a literal instance of a wildcard character in a LIKE pattern, precede it with a backslash. Generally, this is done to match a literal ‘_‘, which occurs frequently in database, table, and column names.

The mysqlshow command provides some of the same information as the SHOW statement, which allows you to get database and table information from the shell:

  • List databases managed by the server:
    % mysqlshow
  • List tables in the named database:
    % mysqlshow db_name
  • Display information about columns in the named table:
    % mysqlshow db_name tbl_name
  • Display information about indexes in the named table:
    % mysqlshow --keys db_name tbl_name
  • Display descriptive information about tables in the named database:
    % mysqlshow --status db_name

The mysqldump utility allows you to see the structure of your tables in the form of a CREATE TABLE statement (much like SHOW CREATE TABLE). When using mysqldump to review table structure, be sure to invoke it with the --no-data option so that you don’t get swamped with your table’s data!

% mysqldump --no-data db_name tbl_name

If you omit the table name, mysqldump displays the structure for all tables in the database.

For both mysqlshow and mysqldump, you can specify the usual connection parameter options (such as --host or --user.)

Determining Which Table Types Your Server Supports

ISAM is the only type available before MySQL 3.23. From 3.23 on, MyISAM, MERGE, and HEAP are always available, and availability of the other types can be assessed by means of an appropriate SHOW VARIABLES statement:

SHOW VARIABLES LIKE 'have_isam';
SHOW VARIABLES LIKE 'have_bdb';
SHOW VARIABLES LIKE 'have_inno%';

If the output from the query shows that the variable has a value of YES, the corresponding table handler is enabled. If the value is something else or there is no output, the handler is unavailable. The use of the pattern have_inno% to determine InnoDB availability matches both have_innodb and have_innobase. (The latter form was used in MySQL 3.23.30 to 3.23.36 before being renamed to have_innodb.)

You can use table type information to determine whether your server supports transactions. BDB and InnoDB are the two transaction-safe table types, so check whether their handlers are enabled as described in the preceding discussion.

As of MySQL 4.1, the list of table types is available directly through the SHOW TABLE TYPES statement:

mysql> SHOW TABLE TYPES;
+--------+---------+-----------------------------------------------------------+
| Type   | Support | Comment                                                   |
+--------+---------+-----------------------------------------------------------+
| MyISAM | DEFAULT | Default type from 3.23 with great performance             |
| HEAP   | YES     | Hash based, stored in memory, useful for temporary tables |
| MERGE  | YES     | Collection of identical MyISAM tables                     |
| ISAM   | YES     | Obsolete table type; Is replaced by MyISAM                |
| InnoDB | YES     | Supports transactions, row-level locking and foreign keys |
| BDB    | YES     | Supports transactions and page-level locking              |
+--------+---------+-----------------------------------------------------------+

The Support value is YES or NO to indicate that the handler is or is not available, DISABLED if the handler is present but turned off, or DEFAULT for the table type that the server uses by default. The handler designated as DEFAULT should be considered available.

Checking a Table’s Existence or Type

It’s sometimes useful to be able to tell from within an application whether or not a given table exists. You can use SHOW TABLES to find out:

SHOW TABLES LIKE 'tbl_name';
SHOW TABLES FROM db_name LIKE 'tbl_name';

If the SHOW statement lists information for the table, it exists. It’s also possible to determine table existence with either of the following statements:

SELECT COUNT(*) FROM tbl_name;
SELECT * FROM tbl_name WHERE 0;

Each statement succeeds if the table exists and fails if it doesn’t. The first statement is most appropriate for MyISAM and ISAM tables, for which COUNT(*) with no WHERE clause is highly optimized. (It’s not so good for InnoDB or BDB tables, which require a full scan to count the rows.) The second statement is more general because is runs quickly for any table type. Use of these queries is most suitable for use within application programming languages, such as Perl or PHP, because you can test the success or failure of the query and take action accordingly. They’re not especially useful in a batch script that you run from mysql because you can’t do anything if an error occurs except terminate (or ignore the error, but then there’s obviously no point in running the query at all).

To determine the type of a table, you can use SHOW TABLE STATUS as of MySQL 3.23.0 or SHOW CREATE TABLE as of MySQL 3.23.20. The output from both statements includes a table type indicator. For versions older than 3.23.0, neither statement is available; but then the only available table type is ISAM, so there is no ambiguity about what storage format your tables use.

Mysql table types

As of MySQL 4.1, the list of table types is available directly through the SHOW TABLE TYPES statement:

mysql> SHOW TABLE TYPES;
+--------+---------+-----------------------------------------------------------+
| Type   | Support | Comment                                                   |
+--------+---------+-----------------------------------------------------------+
| MyISAM | DEFAULT | Default type from 3.23 with great performance             |
| HEAP   | YES     | Hash based, stored in memory, useful for temporary tables |
| MERGE  | YES     | Collection of identical MyISAM tables                     |
| ISAM   | YES     | Obsolete table type; Is replaced by MyISAM                |
| InnoDB | YES     | Supports transactions, row-level locking and foreign keys |
| BDB    | YES     | Supports transactions and page-level locking              |
+--------+---------+-----------------------------------------------------------+