(for more database related articles)
Please find the below link for the transfer login task
http://support.microsoft.com/kb/246133
(for more database related articles)
(for more database related articles)
GRANT OPTION
privileges:GRANT REPLICATION SLAVE, REPLICATION CLIENT
ON *.*
TO 'replicant'@'slave_host'
IDENTIFIED BY 'newpassowrd';
GRANT REPLICATION SLAVE, REPLICATION CLIENT
ON *.*
TO 'replicant'@'master_host'
IDENTIFIED BY 'newpassowrd';
my.cnf
or my.ini
. On Unix-type systems, the configuration file is usually located in the /etc directory. On Windows systems, it's usually located in c:\ or in c:\Windows. Using a text editor, add the following lines to the configuration file, under the [mysqld]
group heading:server-id = 1
log-bin = /var/log/mysql/bin.log
server-id = 2
master-host = masterservernameoripaddressmaster-port = 3306
master-user = replicant
master-password = newpassword
log-bin = /var/log/mysql/bin.log
log-bin-index = /var/log/mysql/log-bin.index
log-error = /var/log/mysql/error.log
relay-log = /var/log/mysql/relay.log
relay-log-info-file = /var/log/mysql/relay-log.info
relay-log-index = /var/log/mysql/relay-log.index
log-error
option establishes an error log. If you don't already have this set up, you should, since it's where any problems with replication will be recorded. The last stanza establishes the relay log and related files mentioned earlier. The relay log makes a copy of each entry in the master server's binary log for performance's sake, the relay-log-info-file
option names the file where the slave's position in the master's binary log will be noted, and the relay log index file is for keeping track of the name of the current relay log file to use for replicating.(for more database related articles)
Explain Varchar and Nvarchar
VARCHAR and NVARCHAR data types are both character data types that are variable-length. Below is the summary of the differences between these 2 data types:
| VARCHAR(n) | NVARCHAR(n) |
Character Data Type | Non-Unicode Data | Unicode Data |
Maximum Length | 8,000 | 4,000 |
Character Size | 1 byte | 2 bytes |
Storage Size | Actual Length (in bytes) | 2 times Actual Length (in bytes) |
We would use NVARCHAR data type for columns that store characters from more than one character set or when we will be using characters that require 2-byte characters, which are basically the Unicode characters such as the Japanese Kanji or Korean Hangul characters.
Explain Varchar(MAX), Nvarchar(MAX) and Varbinary(MAX)
MAX indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of data entered + 2 bytes. The data entered can be 0 characters in length.
We can also declare local variables of VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) data types. This is unlike the data types (TEXT, NTEXT and IMAGE). These enhanced data types are replacing because declaring local variables of TEXT, NTEXT and IMAGE data types is not allowed in the previous versions of SQL Server.
Explain XML Data type
We can create variables, parameters, and columns of the xml type. We can optionally associate a collection of XML schemas with a variable, parameter, or column of xml type and this type of xml instance is call typed and if we will not associate xml schemas with the XML Data Type than it is called untyped.
(for more database related articles)
MYSQL Optimization Tips
The MySQL database server performance depends on the number of factors. The Optimized Query is one of the factors for the MySQL robust performance.
The MySQL performance depends on the below factors.
· Choose compiler and compiler options.
· Find the best MySQL startup options for your system (my.ini/my.cnf).
· Use EXPLAIN SELECT, SHOW VARIABLES, SHOW GLOBAL STATUS, SHOW GLOBAL STATUS and SHOW PROCESSLIST.
· Optimize your table formats.
· Maintain your tables (myisamchk, CHECK TABLE, OPTIMIZE TABLE).
· Use MySQL extensions to get things done faster.
· Write a MySQL UDF function if you notice that you would need some function in many places.
· Don't use GRANT on table level or column level if you don't really need it
· Use Index columns in joins
· Use better data types for the table design. (i.e. “INT” data type is better than “BIG INT” data type)
· Increase the use of “NOT NULL” at table level, that will save some bits
· Do not use UTF8 where you do not need it. UTF8 has 3 times more space reserved. Also UTF8 comparison and sorting is much more expensive. Only use UTF8 for mixed charset data
· Use staraight_join instead of inner join
· Use joins instead of “IN” or “Sub-Queries”
· Decide the database engine for the table by most effective way. (INNODB, MEMORY, ARCHIVE etc)
· INNODB database engine needs more performance and tuning for the MySQL Server & Query optimization.
· Try to create Unique Index. Avoid duplicate data in the index columns.
· Beware of Large Limit
• LIMIT 1000000, 10 can be slow. Even Google does not let you to page 100000. If large number of groups use
SQL_BIG_RESULT hint. Use FileSort instead of temporary table
· USE Index hints (INDEX/FORCE INDEX/IGNORE INDEX) (i.e SELECT * FROM Country IGNORE INDEX(PRIMARY)). This will give the advice to MySQL for the Index Use.
· Use “UNION ALL” instead of “UNION”
· Do not normalize the schema up to more than 3rd Level NF
· Avoid the use of cursors in the stored procedure if not required.
· Avoid the use DDL statements in the stored procedure if not required.
· Use SQL for the things it's good at, and do other things in your application. Use the MySQL server to:
· Find rows based on WHERE
clause.
· JOIN
tables
· GROUP BY
· ORDER BY
· DISTINCT
Don't use MySQL server:
· To validate data (like date)
· As a calculator
· Use keys wisely.
· Keys are good for searches, but bad for inserts / updates of key columns.
· Keep by data in the 3rd normal database form, but don't be afraid of duplicating information or creating summary tables if you need more speed.
· Instead of doing a lot of GROUP BY
s on a big table, create summary tables of the big table and query this instead.
· UPDATE table set count=count+1 where key_column=constant
is very fast!
· For log tables, it's probably better to generate summary tables from them once in a while than try to keep the summary tables live.
· Take advantage of default values on INSERT
.
· Use Index columns in joins
· Use the explain command
Use multiple-row INSERT statements to store many rows with one SQL statement.
The explain command can tell you which indexes are used with the specified query and many other pieces of useful information that can help you choose a better index or query.
Example of usage: explain select * from table
Explanation of row output:
o table—The name of the table.
o type—The join type, of which there are several.
o possible_keys—This column indicates which indexes MySQL could use to find the rows in this table. If the result is NULL, no indexes would help with this query. You should then take a look at your table structure and see whether there are any indexes that you could create that would increase the performance of this query.
o key—The key actually used in this query, or NULL if no index was used.
o key_len—The length of the key used, if any.
o ref—Any columns used with the key to retrieve a result.
o rows—The number of rows MySQL must examine to execute the query.
o extra—Additional information regarding how MySQL will execute the query. There are several options, such as Using index (an index was used) and Where (a WHERE clause was used).
· Use less complex permissions
The more complex your permissions setup, the more overhead you have. Using simpler permissions when you issue GRANT statements enables MySQL to reduce permission-checking overhead when clients execute statements.
· Specific MySQL functions can be tested using the built-in “benchmark” command
If your problem is with a specific MySQL expression or function, you can perform a timing test by invoking the BENCHMARK() function using the mysql client program. Its syntax is BENCHMARK(loop_count,expression). The return value is always zero, but mysql prints a line displaying approximately how long the statement took to execute
· Optimize where clauses
o Remove unnecessary parentheses
o COUNT(*) on a single table without a WHERE is retrieved directly from the table information for MyISAM and MEMORY tables. This is also done for any NOT NULL expression when used with only one table.
o If you use the SQL_SMALL_RESULT option, MySQL uses an in-memory temporary table
· Run optimize table
This command de-fragments a table after you have deleted/inserted lots of rows into table.
· Avoid variable-length column types when necessary
For MyISAM tables that change frequently, you should try to avoid all variable-length columns (VARCHAR, BLOB, and TEXT). The table uses dynamic row format if it includes even a single variable-length column.
· Insert delayed
Use insert delayed when you do not need to know when your data is written. This reduces the overall insertion impact because many rows can be written with a single disk write.
· Use statement priorities
o Use INSERT LOW_PRIORITY when you want to give SELECT statements higher priority than your inserts.
o Use SELECT HIGH_PRIORITY to get retrievals that jump the queue. That is, the SELECT is executed even if there is another client waiting.
· Use multiple-row inserts
Use multiple-row INSERT statements to store many rows with one SQL statement.
· Synchronize data-types
Columns with identical information in different tables should be declared to have identical data types so that joins based on the corresponding columns will be faster.
o MySQL has a rich set of different types. You should try to use the most efficient type for each column.
o The ANALYSE
procedure can help you find the optimal types for a table: SELECT * FROM table_name PROCEDURE ANALYSE()
o Use NOT NULL
for columns which will not store null values. This is particularly important for columns which you index.
o Change your ISAM tables to MyISAM.
o If possible, create your tables with a fixed table format.
o Don't create indexes you are not going to use.
o Use the fact that MySQL can search on a prefix of an index; If you have and INDEX (a,b)
, you don't need an index on (a)
.
o Instead of creating an index on long CHAR
/VARCHAR
column, index just a prefix of the column to save space. CREATE TABLE table_name (hostname CHAR(255) not null, index(hostname(10)))
o Use the most efficient table type for each table.
o Columns with identical information in different tables should be declared identically and have identical names.
o Using >, >=, =, <, <=, IF NULL and BETWEEN on a key.
o SELECT * FROM table_name WHERE key_part1=1 and key_part2 > 5;
o SELECT * FROM table_name WHERE key_part1 IS NULL;
o When you use a LIKE that doesn't start with a wildcard.
o SELECT * FROM table_name WHERE key_part1 LIKE 'jani%'
o Retrieving rows from other tables when performing joins.
o SELECT * from t1,t2 where t1.col=t2.key_part
o Find the MAX()
or MIN()
value for a specific index.
o SELECT MIN(key_part2),MAX(key_part2) FROM table_name where key_part1=10
o ORDER BY
or GROUP BY
on a prefix of a key.
o SELECT * FROM foo ORDER BY key_part1,key_part2,key_part3
o When all columns used in the query are part of one key.
o SELECT key_part3 FROM table_name WHERE key_part1=1
(for more database related articles)
Databases are the heart and soul of many of the recent enterprise applications and it is very essential to pay special attention to database programming. I've seen in many occasions where database programming is overlooked, thinking that it's something easy and can be done by anyone. This is wrong. For a better performing database you need a real DBA and a specialist database programmer, let it be Microsoft SQL Server, Oracle, Sybase, DB2 or whatever! If you don't use database specialists during your development cycle, database often ends up becoming the performance bottleneck. I decided to write this article, to put together some of the database programming best practices, so that my fellow DBAs and database developers can benefit!