Tag Archive | "MySQL"

20 tips on converting MySQL views to MS SQL


20 tips on converting MySQL views to MS SQL

Although there are many free tools and solutions to migrate MySQL data to MS SQL server, none of them is able to convert views. That’s why everybody who wants to migrate complete database have to convert views manually. This article gives 20 tips how to modify MySQL views to make it compatible with Microsoft SQL Server. The target audience for this guide should have general database management knowledge and experience in composing SQL queries.

First, you necessitate to get list of all views in database as follows:

SELECT table_name, view_definition FROM information_schema.views WHERE table_schema=’abase name%’;

And then start to modify each MS SQL view query according to the following rules:

if the query contains ‘ORDER BY…’ clause, it is necessary to insert ‘TOP 100 PERCENT’ right after ‘SELECT’ keywordreplace all occurrenced of ‘now()’ by ‘getdate()’replace ‘JOIN … WHERE’ by ‘CROSS JOIN … WHERE’replace ‘isnull(%expression%)’ by ‘%expression% is null’replace all occurrenced of ‘from_unixtime(%expression%)’ by ‘DateAdd(ss, %expression%, ’01-01-1970′)cut off codepage conversions (like ‘_cp1252′) if any, since it is pure MySQL syntaxreplace ‘curdate()’ by ‘getdate()’replace ‘timediff(%expr1%, %expr2%)’ by ‘CAST(%expr1% – %expr2% AS TIME)’replace ‘%table1% cross join %table2% on %condition%’ by ‘%table1% cross join %table2% where %condition%’replace ‘conact(%expr1%, %expr2%, …, %exprN%)’ by ‘%expr1% + %expr2% + … + %exprN%’replace ‘SELECT … LIMIT %number_of_rows%’ by ‘SELECT TOP %number_of_rows% …’replace ‘RAND()’ by ‘newID()’ – it works in MS SQL 2005 and higherreplace ‘DAY(%expression%)’ or ‘DAYOFMONTH(%expression%)’ by ‘DATENAME(d, %expression%)’replace ‘DAYOFYEAR(%expression%)’ by ‘DATENAME(dy, %expression%)’replace ‘DAYNAME(%expression%)’ by ‘DATENAME(dw, %expression%)’replace ‘HOUR(%expression%)’ by ‘DATENAME(hh, %expression%)’MySQL ‘… like %template%’ is equal to ‘CONTAINS(…, ‘template’)’ in MS SQLMySQL ‘%expression% – INTERVAL 1 DAY’ is equal to MS SQL ‘dateAdd(day, -1, %expression%)’MySQL ‘%expression% – INTERVAL 1 MONTH’ is equal to MS SQL ‘dateAdd(month, -1, %expression%)’MySQL ‘%expression% – INTERVAL 1 YEAR’ is equal to MS SQL ‘dateAdd(year, -1, %expression%)’

Also you should remember that unlike MySQL MS SQL requires all selected columns in ‘SELECT … GROUP BY …’ queries to be either under ‘GROUP BY’ clause or in aggregation functions.

Of course, there are a lot of newances staying outside of this article, it just covering the most frequent issues in migrating views from MySQL to MS SQL. If you need a solution for complete migration of MySQL database to MS SQL server, take a look at the following tools:

MySQL-to-MSSQL by Intelligent Converters – is inexpensive database migartion tool that converts about 50% of views in my tests. The price is $ 49. More details can be found at http://www.convert-in.com/sql2mss.htmDBConvert for MS SQL & MySQL by DMSoft Technologies – bi-directional database migration tool that allows to convert MS SQL to MySQL and vice versa. Non of my test views has been converted. The price is $ 99. More details can be found at http://dbconvert.com/convert-mssql-to-mysql-pro.phpSqlTran by Spectralcore – sophistecated database translator that converts data, stored procedured, triggers and views. I don’t have information about quality of conversion but vendor promises 100% result. The price is $ 999. More details can be found at http://www.sqltran.com/

Posted in JavaComments (0)

MySQL Synchronization


MySQL Synchronization

“XML-RPC is an effective solution to compare and synchronize My SQL databases.”

Features of XML-RPC:

Instantly compare and synchronize your MySQL databases
Compares and synchronizes columns, indexes, constraints
Built-in color-coded SQL difference viewer
Built-in color-coded SQL script editor
Sync different MySQL server versions
Command-line support
Choose which sync actions to skip
Easily handles huge databases
Runs on all Windows versions, Vista x64 included
Features at a glance
Full support for MySQL 5

What is XML- RPC?

XML-RPC is a powerful and user-friendly tool for MySQL data comparison and synchronization. This effective tool compares the data for selected tables in two databases, view differences and update them quickly and safely.

Its flexible comparison and synchronization settings will allows you to set up a customized comparison key and choose the tables and fields for comparison and for synchronization.

This innovative tool also supports using a MySQL server as a write-only client.

Thus, for example, SAP Application users with MaxDB, can easily synchronize key data to a separate MySQL server for business aptitude or reporting purposes.

The Synchronization Manager allows you to set up data synchronization parameters from one MaxDB to one or several MaxDB servers. The synchronization manager uses a standardized XML-RPC to enable asynchronous data transfer. Also, its user-friendly GUI will simplify the definition of the MySQL Synchronization process.

“XML-RPC is an effective solution to compare and synchronize My SQL databases.”

Features of XML-RPC:

Instantly compare and synchronize your MySQL databases
Compares and synchronizes columns, indexes, constraints
Built-in color-coded SQL difference viewer
Built-in color-coded SQL script editor
Sync different MySQL server versions
Command-line support
Choose which sync actions to skip
Easily handles huge databases
Runs on all Windows versions, Vista x64 included
Features at a glance
Full support for MySQL 5

What is XML- RPC?

XML-RPC is a powerful and user-friendly tool for MySQL data comparison and synchronization.

This effective tool compares the data for selected tables in two databases, view differences and update them quickly and safely.

Its flexible comparison and synchronization settings will allows you to set up a customized comparison key and choose the tables and fields for comparison and for synchronization.

This innovative tool also supports using a MySQL server as a write-only client. Thus, for example, SAP Application users with MaxDB, can easily synchronize key data to a separate MySQL server for business aptitude or reporting purposes.

The Synchronization Manager allows you to set up data synchronization parameters from one MaxDB to one or several MaxDB servers. The synchronization manager uses a standardized XML-RPC to enable asynchronous data transfer. Also, its user-friendly GUI will simplify the definition of the MySQL Synchronization process.

 

Pankaj Gupta Writes for OnlineSynchronization.com, a online guide for   databse synchronization and MySQL Synchronization

Related Sql Articles

Posted in DevelopmentComments (2)

Oracle and MySQL


Oracle and MySQL

Some of heard of SQL by Microsoft, and now, most have also heard of MySQL by Oracle Corporation.  What exactly is MySQL?  And why does it seem to always be in computer server news articles and ads?

MySQL can formally be defined as a database management system, of which is relational.  It actually runs as its very own computer server, providing access for numerous users to several and variant database systems.

Named after the daughter of Michael Widenius, developer of the system, it was originally created and began the marketing process in nineteen hundred and ninety-four.  Now, after its formal internal release in nineteen hundred and ninety-five, this database management system is formally owned by Oracle Corporation.

Currently MySQL is being overloaded, and is said to be not capable of holding such large amounts of data.

As personnel and IT experts work around the clock to solve the issue, more and more companies are buying into MySQL or Microsoft’s SQL to save money, anyway.

Oracle is presently claiming that their MySQL management system actually saves a company up to ninety percent more of the cost that Microsoft’s SQL server might.  Some take this to be a battle cry between Oracle and Microsoft, while others see it as healthy competition between one company and another.

Oracle Corporation has also stated that MySQL is to have a complete update and revamp, which should include, but is not limited to:  data modeling tools, new and improved online backups, admin tools, better and newer graphing systems, etc.  Even with the updates, the some are questioning the large price saving gap Oracle is selling to its customers and prospects, with respects to claiming cost efficiency over their current competitors.

Most believe that the Oracle system is going to outweigh the SQL system in the end, but most aren’t making formal statements at this time. There are still very visible gaps with respects to features each system holds, and capabilities each company is attempting to tweak.  And, until capabilities for holding and housing more data is available, some prospective clients are standing still.

Technology is consistently changing, and both Oracle and Microsoft have been in the forefront of positive global advancement and change.  It will be interesting to see what the next step will be for either company, with respects to MySQL and SQL.

About the Author: Steve Oono is the VP of Sales for Mojo Systems. They are the leading industry provider of the HP server, Oracle server, Fujitsu computer hardware and Sun computer server.  For more information, please visit http://www.gotomojo.com.

Posted in DevelopmentComments (1)

Migrate MySQL Database


Migrate MySQL Database

Migrate MySQL Database


Free Online Articles Directory




Why Submit Articles?
Top Authors
Top Articles
FAQ
ABAnswers

Publish Article

0 && $ .browser.msie ) {
var ie_version = parseInt($ .browser.version);
if(ie_version Login


Login via


Register
Hello
My Home
Sign Out

Email

Password


Remember me?
Lost Password?

Home Page > Business > Business Opportunities > Migrate MySQL Database

Categories
AdvertisingArts & EntertainmentAutomotiveBeautyBusinessCareersComputersEducationFinanceFood and BeverageHealthHobbiesHome and FamilyHome ImprovementInternetLawMarketingNews and SocietyRelationshipsSelf ImprovementShoppingSpiritualitySports and FitnessTechnologyTravelWriting

Migrate MySQL Database

By: Drive Recovery Software
Posted: Sep 23, 2009


Migrate MySQL Database

MySQL database converter software converts MySQL database into MSSQL database

Tuesday, September 22, 2009;

 

MySQL database migration application is a powerful tool which converts MySQL table records into MSSQL database server and maintains database integrity constraints. MySQL to MSSQL database converter software provides install and uninstall support.

MySQL database migrator utility can convert selected records or all data records from MySQL database to MSSQL database. Shareware database migration tool provides GUI interface, so non technical person can easily operate this software. MySQL converter utility supports step by step installation with help manual. DB conversion tool can be installed any windows operating systems. Database converter tool provides facility to overwrite or merge converted database into existing database.

MySQL to MSSQL database converter utility systematically and easily converts MySQL database records to MSSQL database. Professional MySQL to MSSQL converter software supports all attributes, schema, table, row, column, primary key, integrity constraints, index, views, triggers, data types, default value, not null and many more. MySQL database migration application provides install and uninstall support. Shareware database migration tool is economic, user friendly, secure and non destructive, so technical and non technical person does not require any technical training. MySQL database migration tool can merge one table or full records of existing MySQL database to MSSQL database records and saves at new location. Professional MySQL to MSSQL database converter utility saves valuable time and money. MySQL to MSSQL database converter application is easy to use and provides wizard style GUI interface. Shareware database migration software provides password protected database files conversion and maintain database integrity during conversion. Database migrator shareware provides free demo version to evaluate its features and functions. MySQL to MSSQL database converter converts large database record regardless of its length and complexity. * Shareware database migration software has attractive features with help manual. * MySQL database converter application can be installed at any windows operating systems. * MySQL to MSSQL database transformation utility provides GUI interface. * Professional MySQL to MSSQL database converter software maintains integrity constraints. * Db migrator supports all version of MySQL and MSSQL databaseShareware database migration software is a powerful tool which easily converts MySQL to MSSQL database server. Professional MySQL converter utility can be installed on any windows operating systems such as windows 2000, windows 2003, windows XP, windows NT, windows vista etc. MySQL to MSSQL database converter application supports step by step installation with help manual and can work with all major versions of MySQL.MySQL database migration application transforms MySQL database to MSSQL database. Professional MySQL converter utility maintains integrity constraints. MySQL database migration tool provides GUI interface, so users can easily operate this software.

For more details you can visit the following URL:

http://www.p-dd.co.in/drive-recovery-software/mysqltomssql.html

For all commercial enquiries please contact

Customer care executive

Email: subsoft@p-dd.co.in

Website: http://www.p-dd.co.in

###

 

Drive Recovery Software – About the Author:

For more details you can visit the following URL:

http://www.p-dd.co.in/drive-recovery-software/mysqltomssql.html

For all commercial enquiries please contact

Customer care executive

Email: subsoft@p-dd.co.in

Website: http://www.p-dd.co.in

Source: http://www.articlesbase.com/business-opportunities-articles/migrate-mysql-database-1262368.html

Increase your traffic today just by submitting articles with us, click here to get started.

Liked this article? Click here to publish it on your website or blog, it’s free and easy!

Rate this Article

1
2
3
4
5

vote(s)
0 vote(s)

Feedback
Print





0) {
ch_selected = Math.floor(Math.random()*ch_queries.length);
if(ch_selected == ch_queries.length) ch_selected–;
ch_query = ch_queries[ch_selected];
}
}catch(e){
ch_query = document.title;
}
]]>

Article Tags:
migrate, mysql, converter, mssol, utility, data, application, database, server, software, primary, key, null, value, shareware, index, program, trigger, table, row, entity, schema, unicode, windows, unique, views, records, constraints

Latest Business Opportunities Articles
More from Drive Recovery Software

What Really Counts in Piece Counting: Best Practices Webinar

METTLER TOLEDO announces the newest installment of its on-demand webinar series, “Best Practices in Piece Counting.” The webinar offers essential piece-counting principals and addresses how manufacturers can optimize piece-counting efforts for better quality control, less product giveaway, and enhanced profits.

By: Marie-Louise

Business >
Business Opportunities
May 24, 2011

Mobile insurance – Not well known to many individuals owning mobile phones

In today’s society almost everyone uses a mobile phone. Most people may not be aware that mobile phones can also be insured. Sometimes, insurance is offered right at the time of purchase of mobile phones. At these times it depends on the customer if it wants to rely on insurance or not.

By: daffareddy

Business >
Business Opportunities
May 24, 2011

China Inspection, Wholesale & Online Risk Management

Seabatis is an International Inspection company at Asia in China providing verification and Inspection services to ensure the business standards of Suppliers and reducing business risks to the Buyers.

By: Infogravity

Business >
Business Opportunities
May 24, 2011

Safest Way to Online Trading

At SEABATIS are mainly focused into the safety measures of online trading to secure buyers from fraudulent companies. They are ahead in certification standards by continual assessment in all aspects of quality. .

By: Infogravity

Business >
Business Opportunities
May 24, 2011

Speed Camera Locators – Helping You Save Your Driving License

GPS Laser GPS based speed camera locators and detectors are undoubtedly among the must-buy devices for drivers. These devices are essential for you for saving your driving license. And I mean it. A detector detects and warns drivers of potential speed trap areas where there may be Specs Cameras, Gatso or laser guns from the back of police vans. The device will warn the driver with a combination of audio and visual signals, such as a series of beeps and signs on the display.

By: Jacob Watson

Business >
Business Opportunities
May 24, 2011

Send SMS From PC to Mobile

PC to mobile text messaging software facilitates business users to get connected with their clients anytime worldwide without any use of internet connection. Bulk text messaging utility helps to transmit unlimited number of messages from your personal computer connected with Windows mobile and Microsoft ActiveSync. SMS broadcasting tool allows you to enter sender phone number either manually or load from cell phone book memory.

By: Drive Recovery Software

Internet
Sep 05, 2009
Comments: 1

MDB to MySQL Converter

MS Access to MySQL database converter program converts whole database or selected data tables, rows, columns with all data types and key constraints including default value, null values, indexes, triggers, schemas, primary, foreign key etc. Access database migration software overwrites converted MS Access database records into existing MySQL database and facilitates users to save converted records at desired location without any single change.

By: Drive Recovery Software

Business >
Entrepreneurship
Jun 29, 2009

Comments on this article [0]
Add new Comment

Related Videos


Dreamweaver CS3 and ColdFusion – How to Restore the…


How to create a MySql database


Dreamweaver CS3 and ColdFusion – How to Install the…

Ask a question

Ask our experts your Business Opportunities related questions here…

200 Characters left

Related Questions

What are primary keys and foreign keys?
What are the key elements of an ethics program?
What application layer protocol it use Seo applications? What type of service it needs from the network? How can describe the Seo applications and Is Seo client-server or P2P application?

Need Help?
Contact Us
FAQ
Submit Articles
Editorial Guidelines
Blog

Site Links
Recent Articles
Top Authors
Top Articles
Find Articles
Site Map
Mobile Version

Webmasters
RSS Builder
RSS
Link to Us

Business Info
Advertising

Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2011 Free Articles by ArticlesBase.com, All rights reserved.


Article from articlesbase.com

Posted in DevelopmentComments (24)

Aghreni Technologies Educational Services – Trainings on Open Source Technologies ( Perl, Php, Java, Ruby, Linux, Mysql)


Aghreni Technologies Educational Services – Trainings on Open Source Technologies ( Perl, Php, Java, Ruby, Linux, Mysql)

 Aghreni offers skill enhancement courses in 

· PErL, PHP, Ruby & java/J2ee

· Unix/linux

· Mysql

· Web development

· User interface design

·  Veritas

· Usability engineering

· Project management

· Leadership

· Software development techniques

· Software testing techniques

Posted in JavaComments (0)

More on SQL and MySQL


More on SQL and MySQL

PHP – In this section we discuss miscellaneous tools and techniques for using SQL and MySQL. We introduce:

Choosing keys and indexes for fast searching

Elementary database-tuning techniques

Adding and deleting users of a DBMS, and changing user permissions

Limitations of MySQL

3.10.1 Keys, Primary Keys, and Indexes
As discussed earlier in our introduction to SQL, each table should have a PRIMARY KEY definition as part of the CREATE TABLE statement. A primary key is an attribute—or set of attributes—that uniquely identifies a row in a table. Storing two rows with the same primary key isn’t permitted and, indeed, an attempt to INSERT duplicate primary keys produces an error.

In MySQL, the attribute values of the primary key are stored in an index to allow fast access to a row. The default MySQL index type is fast for queries that find a specific row, a range of rows, for joins between tables, grouping data, ordering data, and finding minimum and maximum values. Indexes don’t provide any speed improvement for retrieving all the rows in a table or for other query types.

Indexes are also useful for fast access to rows by values other than those that are associated with attributes in the primary key. For example, in the customer table, you might define an index by adding the clause:

KEY namecity (surname,firstname,city)
to the CREATE TABLE statement. After you define this index, some queries that select a particular customer through a WHERE clause can use it. Consider an example:

SELECT * FROM customer
WHERE surname = ‘Marzalla’ AND
firstname = ‘Dimitria’ AND
city = ‘St Albans’;
This query can use the new index to locate—in at most a few disk accesses—the row that matches the search criteria. Without the index, the DBMS must scan all the rows in the customer table and compare each row to the WHERE clause. This might be quite slow and certainly requires significantly more disk accesses than the index-based approach (assuming the table has more than a few rows).

A particular feature of DBMSs is that they develop a query evaluation strategy and optimize it without any interaction from the user or programmer. If an index is available, and it makes sense to use it in the context of a query, the DBMS does this automatically. All you need to do is identify which queries are common, and make an index available for those common queries by adding the KEY clause to the CREATE TABLE statement or using ALTER TABLE on an existing table.

Careful index design is important. The namecity index we have defined can also speed queries other than those that supply a complete surname, firstname, and city. For example, consider a query:

SELECT * FROM customer
WHERE surname = ‘LaTrobe’ AND
firstname = ‘Anthony’;
This query can also use the index namecity, because the index permits access to rows in sorted order first by surname, then firstname, and then city. With this sorting, all “LaTrobe, Anthony” index entries are clustered together in the index. Indeed, the index can also be used for the query:

SELECT * FROM customer
WHERE surname LIKE ‘Mar%’;
Again, all surnames beginning with “Mar” are clustered together in the index. However, the index can’t be used for a query such as:

SELECT * FROM customer
WHERE firstname = ‘Dimitria’ AND
city = ‘St Albans’;
The index can’t be used because the leftmost attribute named in the index, surname, isn’t part of the WHERE clause. In this case, all rows in the customer table must be scanned and the query is much slower (again assuming there are more than a few rows in the customer table, and assuming there is no other index).

Careful choice of the order of attributes in a KEY clause is important. For an index to be usable in a query, the leftmost attribute must appear in a WHERE clause.

There are other cases in which an index can’t be used, such as when a query contains an OR that isn’t on an indexed attribute:

SELECT * FROM customer
WHERE surname = ‘Marzalla’ OR
email = ‘dimitria@lucaston.com’;
Again, the customer table must be completely scanned, because the second condition, email=’dimitria@lucaston.com’, requires all rows to be retrieved as there is no index available on the attribute email. Also, the case where the ORed attribute isn’t the leftmost attribute in an index requires a complete scan of the customer table. The following example requires a complete scan:

SELECT * FROM customer
WHERE firstname = ‘Dimitria’ OR
surname = ‘Marzalla’;
If all the attributes in the index are used in all the queries, to optimize index size, the leftmost attribute in the KEY clause should be the attribute with the highest number of duplicate entries.

Because indexes speed up queries, why not create indexes on all the attributes you can possibly search on? The answer is that while indexes are fast for searching, they consume space and require updates each time rows are added or deleted, or key attributes are changed. So, if a database is largely static, additional indexes have low overheads, but if a database changes frequently, each additional index slows the update process significantly. In either case, indexes consume additional space, and unnecessary indexes should be avoided.

One way to reduce the size of an index and speed updates is to create an index on a prefix of an attribute. Our namecity index uses considerable space: for each row in the customer table, an index entry is up to 120 characters in length because it is created from the combined values of the surname, firstname, and city attributes.[2] To reduce space, you can define the index as:

[2] This isn’t the space actually required by an index entry, because the data is compressed for storage. However, even with compression, the fewer characters indexed, the more compact the representation, the more space saved, and—depending on the usability of the index—the faster searching and updates are.

KEY namecity (surname(10),firstname(3),city(2));
This uses only the first 10 characters of surname, 3 of firstname, and the first 2 characters of city to distinguish index entries. This is quite reasonable, because 10 characters from a surname distinguishes between most surnames, and the addition of a few characters from a first name and the prefix of their city should be sufficient to uniquely identify almost all customers. Having a smaller index with less information can also mean that queries are actually faster, because more index information can be retrieved from disk per second, and disk retrieval speed is almost always the bottleneck in query performance.

The space saving is significant with a reduced index. A new index entry requires only 15 characters, a saving of up to 105 characters, so index insertions, deletions, and modifications are now likely to be much faster. Note that for TEXT and BLOB attribute types, a prefix must be taken when indexing, because indexing the entire attribute is impractical and isn’t permitted by the MySQL DBMS.

3.10.2 Tuning the Database System
Careful index design is one technique that improves the speed of a DBMS and can reduce the resource requirements of a database. However, comprehensive database tuning is a complex topic that fills many books. We include in this section only a few additional practical ideas to begin to improve the performance of a database system.

As discussed previously, accessing a hard disk is slow and is usually the bottleneck in DBMS performance. More specifically, disk seeking—moving the disk head to get information from another location of the disk—is the slowest component of disk access. Therefore, most techniques described in this section are also techniques that improve performance by minimizing disk space requirements.[3]

[3] Reducing disk space requirements improves both disk seek and read performance. Disk read performance is improved because less data is required to be transferred, while seek performance is improved because the disk head has to move less on average when randomly accessing a smaller file than when accessing a larger file.

Here are some ways to improve DBMS performance:

Carefully choose attribute types and lengths. Where possible, use small variants such as SMALLINT or MEDIUMINT rather than the regular choice INT. When using fixed-length attributes, such as CHAR, specify a length that is as short as practical.

Use fixed-length attributes; that is, try to avoid types such as VARCHAR or BLOB. While fixed-length text attributes may waste space, scanning fixed-length rows in a query is much faster than scanning variable-length rows.

Design indexes with care. As discussed in the last section, keep the primary key index as small as possible, create only indexes that are needed, and use prefixes of attributes where possible. Ensure that the leftmost attribute in the index is the most frequently used in queries and, if all attributes are used, make sure the leftmost attribute is the one with the highest number of duplicate entries.

Create a statistics table if aggregate functions such as COUNT( ) or SUM( ) are frequently used in queries on large tables. A statistics table stores only one row that is manually updated with the aggregate values of another table. For example, if the statistics table maintains the count of rows in a large customer table, each time a row is inserted or deleted in the customer table, the count is updated in the statistics table. For large tables, this is often faster than calculating aggregate functions with the slow built-in functions that require complete processing of all rows.

If large numbers of rows are deleted from a table, or a table containing variable-length attributes is frequently modified, disk space may be wasted. MySQL doesn’t usually remove deleted or modified data; it only marks the location as being no longer in use. Wasted space can affect access speed.

To reorganize a table—by copying data to a temporary location and back again—MySQL provides the OPTIMIZE TABLE command, which should be used periodically. For example:

OPTIMIZE TABLE customer;
The OPTIMIZE command should be run when the DBMS is offline for scheduled maintenance. The command is nonstandard SQL.

It is possible to create different table types for specific tasks. The default in MySQL is the MyISAM type, and all the tables described so far are this table type. For small, temporary, frequently used lookup tables, a different type, the heap table type, can be used. There are other types, and we briefly discuss alternatives in Chapter 6. More details are provided in Section 9.4 of the MySQL user manual.

Section 10.7 of the MySQL manual includes other excellent ideas for simple performance improvement.

Another aspect of database tuning is optimizing the performance of the DBMS itself. Included with the MySQL installation is the mysqladmin tool for database administration. Details of the system setup can be found by running the following command from a Linux shell:

% mysqladmin -ppassword variables
This shows, in part, the following selected system parameters:

join_buffer current value: 131072
key_buffer current value: 8388600
net_buffer_length current value: 16384
record_buffer current value: 131072
sort_buffer current value: 2097144
table_cache current value: 64
The important parameters are those that impact disk use. MySQL has several main-memory buffer parameters that control how much data is kept in memory for processing. These include:

The record_buffer for scanning all rows in a table

The sort_buffer for ORDER BY and GROUP BY operations

The key_buffer for storing indexes in main memory

The join_buffer for joins that don’t use indexes

In general, the larger these buffers, the more data from disk is cached or stored in memory and the fewer disk accesses are required. However, if the sum of these parameters is near to exceeding the size of the memory installed in the server, the underlying operating system will start to swap data between disk and memory, and the DBMS will be slow. In any case, careful experimentation based on the application is likely to improve DBMS performance.

Section 10.2.3 of the MySQL manual suggests parameter settings when starting the MySQL server. First, for machines with at least 64 MB of memory, large tables in the DBMS, and a moderate number of users, use:

safe_mysqld -O key_buffer=16M -O table_cache=128 \
-O sort_buffer=4M -O record_buffer=1M &
Second, if there is less than 64 MB of memory available, and there are many users, try the following:

safe_mysqld -O key_buffer=512k -O sort_buffer=100k \
-O record_buffer=100k &
The following setting might be appropriate for the winestore, because many users are expected, the queries are largely index-based, and the database is small:

safe_mysqld -O key_buffer=512k -O sort_buffer=16k \
-O table_cache=32 -O record_buffer=8k
-O net_buffer=1K &
Even more conservative settings might also be acceptable.

There are two other parameters we have not discussed. The table_cache parameter manages the maximum number of open tables per user connection, while the net_buffer parameter sets the minimum size of the network query buffer in which incoming queries are kept before they are executed.

The mysqladmin utility can report the status of the DBMS:

% mysqladmin -ppassword status
The output has the following format:

Uptime: 5721024 Threads: 14 Questions: 7874982
Slow queries: 6 Opens: 115136 Flush tables: 1
Open tables: 62
This gives a brief point-in-time summary of the DBMS status and can help find more about the number of user connections, queries, and table use. Similar output can be generated by running the commands SHOW STATUS and SHOW VARIABLES through the MySQL command interpreter.

Information about query performance can be gained with the benchmark( ) function, which can be used iteratively for tuning when altering table design or DBMS system parameters. The following statement illustrates benchmarking:

SELECT benchmark(10000, COUNT(*))
FROM items;
This statement reports the time taken to evaluate 10,000 calls to COUNT( ) on the items table.

3.10.3 Adding and Deleting Users
We have not yet discussed adding and deleting users from the MySQL DBMS. Our rationale in leaving this topic until this final section is that DBMS users aren’t as important in a web database application as in other applications. Because access to the database and DBMS is generally controlled in the application logic of the middle tier, usually only one or two DBMS users are needed.

A user, hugh, who has full control over all aspects of the DBMS and can access the DBMS from the machine that hosts the DBMS, can be created with the statement:

GRANT ALL PRIVILEGES ON *.* TO hugh@localhost
IDENTIFIED BY ‘password’ WITH GRANT OPTION;
Allowing access over a network can be added with:

GRANT ALL PRIVILEGES ON *.* TO hugh@”%”
IDENTIFIED BY ‘password’ WITH GRANT OPTION;
There is no need to allow network access for a web database application if the middle-tier components—the web server and scripting engine—are installed on the same machine as the DBMS.

This user can then connect to the database from the shell with the command:

% mysql -ppassword -uhugh
The user information is stored in the mysql database in the user table, which can be explored with:

USE mysql;
SELECT * FROM user;
The mysql database and the user table can be managed in the same way as any other database. For example, you can update the password of the new user with the UPDATE statement:

UPDATE user
SET password=password(‘newpwd’)
WHERE user=’hugh’;
Note the use of the password( ) function we described earlier to encrypt the password for storage in the user table.

3.10.3.1 Permissions
Users can be added to the system with an INSERT INTO the user table in the mysql database or, as previously illustrated, you can use the GRANT statement. Moreover, privileges can be adjusted with an UPDATE, added with GRANT, or removed with REVOKE.

Consider the following example:

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON winestore.*
TO dave@localhost
IDENTIFIED BY ‘password’;
This adds a new user dave and allows him to use only the SQL statements listed in the winestore database. The parameter winestore.* means all tables within the winestore database.

Privileges can be removed with the REVOKE statement. For example:

REVOKE DROP,CREATE ON winestore.* FROM dave@localhost;
If the privilege or privileges are to be revoked for all databases in the DBMS, not just a single database, winestore.* can be replaced with *.*.

The following privileges can be used in GRANT and REVOKE statements:

ALL PRIVILEGES, FILE, RELOAD, ALTER, INDEX, SELECT,
CREATE, INSERT, SHUTDOWN, DELETE, PROCESS, UPDATE,
DROP, REFERENCES, USAGE
3.10.4 Limitations of MySQL
The most significant limitation of MySQL is that it doesn’t support nested queries. However, support is planned in MySQL Version 4. Nested queries are those that contain another query. Consider an example nested query to find the wines that have inventory stock:

SELECT DISTINCT wine_id FROM wine
WHERE wine_id IN
(SELECT wine_id from inventory);
The query returns the wine_id values from the wine table that are found in the inventory table. Nested queries use the IN, NOT IN, EXISTS, and NOT EXISTS operators.

In many cases, a nested query can be rewritten as a join query. For example, to find the wines that are in stock, you can use the following join query:

SELECT DISTINCT wine.wine_id FROM wine, inventory
WHERE wine.wine_id = inventory.wine_id;
However, some nested queries can’t be rewritten as join queries; for difficult queries, temporary tables are often a useful workaround.

A limitation of DELETE and UPDATE is that only one table can be specified in the FROM clause. This problem is particular to MySQL and related to the lack of support for nested queries. This limitation can make modifications of data difficult. For example, it prevents data being deleted or updated using the properties of another table. A solution involves data being copied to a temporary table using a combined INSERT and SELECT statement that joins together data from more than one table. Then, the data can be deleted or updated in the temporary table and then transferred back to the original table. Another approach, using the concat( ) string function, is discussed in Section 1.4.4.1 in the MySQL manual.

To avoid UPDATE and DELETE problems, consider adding additional attributes to tables at design time. For example, in the winestore we added a DATE attribute to the items table so that shopping-cart items can be removed easily if they aren’t purchased within one day. Removing rows from the items table based on the DATE in the orders table is difficult without support for nested queries.

MySQL doesn’t support stored procedures or triggers. Stored procedures are queries that are compiled and stored in the DBMS. They are then invoked by the middle-tier application logic, with the benefit that the query is parsed only once and there is less communication overhead between the middle and database tiers. Triggers are similar to stored procedures but are invoked by the DBMS when a condition is met. Stored-procedure support is planned for MySQL, but trigger support isn’t.

Views aren’t supported in MySQL. Views consolidate read-only access to several tables based on a join condition. For example, a view might allow a user to browse the sales made up to April without the need to create a temporary table, as we did in the example in Section 3.8. View support is planned for the future.

Limitations that we don’t discuss here include the lack of support for foreign keys and cursors. More detail on the limitations of MySQL can be found in Section 1.4 of the manual distributed with MySQL.

More PHP Tutorial

Posted in DevelopmentComments (2)

Ajax Rating Script – Php & Mysql


Ajax Rating Script – Php & Mysql

Introduction

Frequent visitors of ajax enabled websites, like ajaxian, have all witnessed them already: ajax rating widgets. They are flashy, animated, you can use them to rate the content (usually without refreshing the page) and if you could, you’d present them to your parents and marry them. Compared to the classic rating system, as on IMDb, they incite people to click them, reducing the effective rating process to only one click.
In this tutorial, I want to show you how to create the JavaScript framework to display the animated rating widget and how to connect it to your server backend by using some of the most common Ajax frameworks out there. I clearly separate the page creation from the JavaScript functions and the rating backend, to allow the script to be as flexible as possible and to be easy integrable into your existing website.
This tutorial is not meant to present you with a finished script (even though you could simply copy&paste the end result into your website and make it work without any problems), but rather to explain the design and implementation process that would enable you to create your own widgets if you’d need to. Getting started with the HTML markup

What It Is

This is a rating bar script done with PHP and mySQL that allows users to rate things like can be done all web 2.0-like with no page refresh. It is a major improvement on the previous version because it is now unobtrusive, meaning that if Javascript is off it will still work (although the page will refresh). You can also set the number of rating units you want to use (i.e. 4 stars, 5 stars, or 10 stars) on a rater to rater basis (see samples below or read the docs). A few other changes were made as well

Related Ajax Articles

Posted in DevelopmentComments (1)

MySQL Vs MsSQL


The best among all data management solutions available today are the MySQL and MsSQL. Although, that both of those solutions are working really good, there are a lot of differences between them and when it comes to choosing, which is the best among them, there are a lot of things that you should know.

View full post on Internet and Businesses Online: Web Hosting Articles from EzineArticles.com

Posted in HostingComments (2)