|
#1
| ||||
| ||||
| What is MySQL? MySQL - An open source database management system developed by MySQL AB, http://www.mysql.com. MySQL was started with mSQL with fast low-level (ISAM) routines. So MySQL and mSQL are having almost the same application programming interfaces and command line interfaces. Main features of MySQL (extracted from MySQL manual):
1. Go to http://dev.mysql.com/downloads and select the latest production release. 2. Go to "Windows downloads" and select "Without installer (unzip in C:\)" entry. 3. Save the downloaded file, mysql-4.0.18-win-noinstall.zip, on your hard disk. 4. Unzip mysql-4.0.18-win-noinstall.zip to "\" and rename "\mysql-4.0.18" to "\mysql". 5. Open a command window and run "\mysql\bin\mysqld" to start MySQL server: Code: \mysql\bin\mysqld --console nnnnnn 22:16:53 InnoDB: Started \local\mysql\bin\mysqld: ready for connections. Version: '4.0.18-max-debug' socket: '' port: 3306 Code: \mysql\bin\mysqladmin pingmysqld is alive\mysql\bin\mysqladmin shutdown Creating First Table in MySQL In the previous section, we learned how to start and shutdown MySQL server. Now let's see how we can use MySQL client interface to create a table and run queries. First start the MySQL server in one command window, then run the start the MySQL client interface in another command window, and run the following MySQL client commands: Code: \mysql\bin\mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.0.18-max-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.06 sec)
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table hello (message varchar(80));
Query OK, 0 rows affected (0.58 sec)
mysql> insert into hello (message) values ('Hello world!');
Query OK, 1 row affected (0.38 sec)
mysql> select * from hello;
+--------------+
| message |
+--------------+
| Hello world! |
+--------------+
1 row in set (0.04 sec)
mysql> drop table hello;
Query OK, 0 rows affected (0.34 sec)
mysql> quit;
Bye
__________________ Knowledgebase | SEO | Free Scripts | Free Graphics | Free Wordpress Themes | Free Word Cloud Script | Domains For Sale | Optimize Your Forum |
![]() Ultimate Wordpress Commenter |
|
#2
| ||||
| ||||
|
What's in MySQL? Programs and tools offered in MySQL:
mysql is very easy to use:
Code: \mysql\bin\mysql --host localhost test
......
mysql> create table hello (message varchar(80));
Query OK, 0 rows affected (0.41 sec)
mysql> insert into hello (message) values ('Hello world!');
Query OK, 1 row affected (0.03 sec)
mysql> select * from hello;
+--------------+
| message |
+--------------+
| Hello world! |
+--------------+
1 row in set (0.00 sec)
mysql> drop table hello;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
Code: -- hello.sql
create table hello (message varchar(80));
insert into hello (message) values ('Hello world!');
select * from hello;
drop table hello; Code: \mysql\bin\mysql --host localhost test ...... mysql> source hello.sql Query OK, 0 rows affected (0.05 sec) Query OK, 1 row affected (0.00 sec) +--------------+ | message | +--------------+ | Hello world! | +--------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) Code: \mysql\bin\mysql --host localhost test < hello.sql message Hello world! Dumping Data into Files - mysqldump mysqldump is a tool to dump table structure and data to files. This tool can be used in different ways. 1. Dump tables of a database as SQL statements into a single file. Table structures will be dumped as create table statements. Data rows will be dumped as insert statements. If table is not specified, all tables will be dumped. Code: \mysql\bin\mysqldump --result-file=file.sql db_name [tbl_name] Code: \mysql\bin\mysqldump --tab=dir_name db_name [tbl_name] Code: \mysql\bin\mysqldump --xml --result-file=file.xml db_name [tbl_name] Code: -- CreateDatabase.sql -- DROP DATABASE IF EXISTS Library; CREATE DATABASE Library; USE Library; -- CREATE TABLE Book (ID INT, Title VARCHAR(64), Author_ID INT); INSERT INTO Book VALUES (1, 'Java', 1); INSERT INTO Book VALUES (2, 'C++', 1); INSERT INTO Book VALUES (3, 'FORTRAN', 2); -- CREATE TABLE Author (ID INT, Name VARCHAR(16)); INSERT INTO Author VALUES (1, 'Taree'); INSERT INTO Author VALUES (2, 'Internet'); -- SELECT Title, Name FROM Book INNER JOIN Author ON Book.Author_ID=Author.ID;
__________________ Knowledgebase | SEO | Free Scripts | Free Graphics | Free Wordpress Themes | Free Word Cloud Script | Domains For Sale | Optimize Your Forum |
|
#3
| ||||
| ||||
| ... continued from previous post Output from this SQL file: Code: Title Name Java Internet C++ Internet FORTRAN Taree Code: \mysql\bin\mysqldump --result-file=Library.sql Library mkdir Library \mysql\bin\mysqldump --tab=Library Library \mysql\bin\mysqldump --xml --result-file=Library.xml Library mysqlimport is a tool to load data stored in files into tables. Data should be stored in files as tab delimited values. Data file names without extensions should match table names. The command line syntax of mysqlimport is: Code: \mysql\bin\mysqlimport db_name file_1, file_2, ... Code: \mysql\bin\mysqlimport Library Library\book.txt Library.book: Records: 3 Deleted: 0 Skipped: 0 Warnings: 0 Installing Perl Database Driver for MySQL Here is what we need to access MySQL from Perl programs:
To install MySQL server, see the previous post, "Installing MySQL". Perl DBI (Database Interface) module is the basic abstraction layer for working with external database servers. If DBI module is not available on your Perl installation, you could to go to http://search.cpan.org/dist/DBI/ and download DBI-1.42.tar.gz. But installing DBI module from the .tar file seems to be too complicated. Another easy way to install the DBI module is to use PPM (Perl Package Management) directly from Internet, if you have ActivePerl installed: Code: \perl\bin\ppm PPM interactive shell (2.1.5) - type 'help' for available commands. PPM> install DBI Install package 'DBI?' (y/N): y Installing package 'DBI'... Bytes transferred: 435739 Installing D:\Perl\site\lib\auto\DBI\dbd_xsh.h Installing D:\Perl\site\lib\auto\DBI\DBI.bs ...... Installing D:\Perl\html\site\lib\DBI.html Installing D:\Perl\html\site\lib\Win32\DBIODBC.html ...... Installing D:\Perl\site\lib\DBI.pm Installing D:\Perl\site\lib\Win32\DBIODBC.pm ...... Installing D:\Perl\bin\dbiprof Installing D:\Perl\bin\dbiprof.bat Installing D:\Perl\bin\dbiproxy Installing D:\Perl\bin\dbiproxy.bat Writing D:\Perl\site\lib\auto\DBI\.packlist PPM> quit Quit! The DBD:mysql module is the database driver for MySQL required by the DBI module. It can also be installed by PPM, if you have ActivePerl installed: Code: \perl\bin\ppm PPM> install DBD-mysql Install package 'DBD-mysql?' (y/N): y Installing package 'DBD-mysql'... Bytes transferred: 179124 Installing D:\Perl\site\lib\auto\DBD\mysql\mysql.bs Installing D:\Perl\site\lib\auto\DBD\mysql\mysql.dll ...... Installing D:\Perl\html\site\lib\Mysql.html Installing D:\Perl\html\site\lib\DBD\mysql.html ...... Installing D:\Perl\site\lib\Mysql.pm Installing D:\Perl\site\lib\Mysql\Statement.pm ...... Writing D:\Perl\site\lib\auto\DBD\mysql\.packlist HelloMySQL.pl - My First Perl Program with MySQL Now we are ready to write a Perl program using the DBI module to access MySQL server. Here my first example, HelloMySQL.pl: Code: # HelloMySQL.pl
use DBI;
$dbh = DBI->connect("DBI:mysql:test");
$dbh->do("create table hello (message varchar(80))");
$dbh->do("insert into hello (message) values ('Hello world!')");
$sth = $dbh->prepare("select * from hello");
$sth->execute();
while ((@row) = $sth->fetchrow_array()) {
print "$row[0]\n";
}
$sth->finish();
$dbh->do("drop table hello");
$dbh->disconnect();
exit; Code: \perl\bin\perl HelloMySQL.pl Hello world!
__________________ Knowledgebase | SEO | Free Scripts | Free Graphics | Free Wordpress Themes | Free Word Cloud Script | Domains For Sale | Optimize Your Forum |
|
#4
| |||
| |||
|
Superb post. Good work. |
|
#5
| |||
| |||
|
MySQL is a relational database management system (RDBMS). My Sql is an Popular Open Source Database and MySQL is an open source database management system. MySQL is runs on both Linux and Windows servers and is commonly used in conjunction with PHP. Last edited by Mike Tyson; 02-10-2009 at 04:02 AM. |
|
#6
| |||
| |||
|
Thanks for the info i have never used it and switching toward mysql reavals me to new complexity is thier any online help or ebook for helping me through this.
|
|
#7
| |||
| |||
|
Great Post! Thanks for giving me such a detailed description of Mysql. |
![]() Ultimate Wordpress Commenter |
![]() |
| Tools | |
| Display Modes | |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How To Backup a MySql Database | Admin | Knowledgebase | 6 | 10-01-2009 10:17 AM |
| MySql - Stored Procedures | Admin | Knowledgebase | 1 | 02-10-2009 04:41 AM |
| Converting mysql result set into an array? | bretheartbobby | Knowledgebase | 2 | 02-11-2008 04:54 PM |
| Installing Apache, PHP, MySql and Perl on Windows | Admin | Knowledgebase | 0 | 04-20-2007 06:47 AM |