MySQL 5.7 InnoDB Tablespace

By default for MySQL server, InnoDB Engine is getting used widely due it’s ACID support, optimized read-write performance and for many other reasons which are great significance for the database server.

In this blog post, we are going to cover the InnoDB tablespace and its features like,

  • InnoDB engine tablespaces
  • Tablespace Data Encryption
  • Tablespace related Configuration

InnoDB engine tablespaces

System tablespace:  

Common tablespace for MySQL server operations. Apart from the table data storage, InnoDB’s functionality requires looking for table metadata, storing and retrieving MVCC info to support ACID compliance and Transaction Isolation. It contains several types of information for InnoDB objects.

  • Contains:
    Table Data Pages
    Table Index Pages
    Data Dictionary
    MVCC Control Data
    Undo Space
    Rollback Segments
    Double Write Buffer (Pages Written in the Background to avoid OS caching)
    Insert Buffer (Changes to Secondary Indexes)
  • Variables:
    innodb_data_file_path = /ibdata/ibdata1:10M:autoextend

    By enabling innodb_file_per_table (the default) option, we can store each newly created table (data and index) in a separate tablespace. Advantage for this storage method is less fragmentation within disk data file.

InnoDB data dictionary:
Storage area in system tablespace made up of internal system tables with metadata information for objets[tables, index, columns etc.]

Double write buffer:
Storage area in system tablespace where innodb writes pages from innodb buffer pool, before writing to their proper location in the data files.
In case mysqld process crash in the middle of a page writes, at the time of crash recovery InnoDB can find a good copy of the page from doublewrite buffer.

Variable: inndb_doublewrite (default enable)

REDO logs:
Use for crash recovery. At the time of mysqld startup, InnoDB performs auto recovery to correct data written by incomplete transactions. Transactions that not finish updating data files before an unexpected mysqld shutdown are replayed automatically at the time of mysqld startup even before taking any connection. It uses LSN(Log Sequence Number) value.
Plenty of data changes can not get written to disk quickly, so it will go under redo and then to the disk.

Why we need a redo for recovery?
Let’s take an example, User changing data in innodb buffer and commit, somewhere it needs to go before writing into a disk. Because in the case of crash buffer data will lost, that’s why we need redo logs.

– In redo, all changes will go with info like row_id, old column value, new column value, session_id and time.
– One commit complete data will under disk in a data file.
– Variables:
Innodb_log_file_in_group= [# of redo file groups]

innodb_log_buffer_size= [ Buffer size ] (Set greater value to hold large transactions in memory. Start from 10-20% of total log files size)

Innodb_log_file_size= [Size for each redo file]  (Should be set to a greater value greater for BLOB data types in database )

UNDO tablespace and logs:

UNDO tablespace contains one or more undo logs files.
UNDO manages consistent reads by keeping modified uncommitted data for active transaction [MVCC]. Unmodified data is retrieved from this storage area.Undo logs also called as rollback segments
By default, UNDO logs are part of system tablespace, MySQL allows to store undo logs in separate UNDO tablespace/s [Introduce in MySQL 5.6]. Need to configure before initializing mysqld server.

– When we configure separate undo tablespace, the undo logs in the system tablespace become inactive.
– Need to configure before initializing mysqld server and can not change after that.
– We truncate undo logs, but can not drop.
– The default initial size of an undo tablespace file is 10MB.
– Variables :
innodb_undo_tablespace : Number of undo tablespaces, default 0 , max 95
innodb_undo_directory : Location for undo tablespace,default is data_dir with 10MB initial size.
innodb_undo_logs : Number of undo logs in a single undo tablespace, default and max value is ‘128’ [ Deprecated in 5.7.19 , innodb_rollback_segments variable will control this]
innodb_undo_log_truncate: truncate undo tablespace, Default OFF  [When enabled, undo tablespaces that exceed the threshold value defined by innodb_max_undo_log_size are marked for truncation. ]

Key Points:

  • Truncating undo logs need separate undo logs. This means undo in system tablespace can not be truncated.
  • innodb_undo_tablespaces must be set to a value equal to or greater than 2.
  • innodb_rollback_segments must set to a value equal to or greater than 35.

Benefits: Reduce the size of the single tablespace (system tablespace), since we are storing long-running transactions into a sperate single/multiple UNDO tablespaces.

Temporary tablespace:

Storage to keep and retrieve modified uncommitted data for temporary tables and related objects.Introduce in MySQL 5.7.2 and use for rollback temp table changes while a server is running.

– Undo logs for temporary tables reside in the temp tablespace.
– Default tablespace file ibtmp1 getting recreated on server startup.
–  Not getting used for crash recovery.
– Advantage: Performance gain by avoiding redo logging IO for temp tables and related objects.
– Variable:
innodb_temp_data_file_path = ibtmp1:12M:autoextend (default)

General tablespace:

Shared tablespace to store multiple table data. Introduce in MySQL 5.7.6. A user has to create this using CREATE TABLESPACE syntax. TABLESPACE option can be used with CREATE TABLE to create a table and ALTER TABLE to move a table in general table.

– Memory advantage over innodb_file_per_table storage method.
– Support both Antelope and Barracuda file formats.
–  Supports all row formats and associated features.
–  Possible to create outside data directory.

Tablespace Data Encryption:

InnoDB supports data encryption for InnoDB tables stored in file-per-table tablespaces using mysql keyring. MySQL 5.7.11 and higher includes a keyring plugin.

keyring_file: Stores keyring data in a file local to the server host. keyring_file must be loaded at each server startup using the –early-plugin-load option

keyring_okv: Back end keyring storage products such as Oracle Key Vault, This plugin is available in MySQL Enterprise Edition distributions.

Variables:
early-plugin-load : Settings ensure that plugin is available prior to initialization of the InnoDB storage engine.
keyring_file_data : keyring file path.

Tablespace related Configuration and operations:

MySQL InnoDB Configuration:

## DATA STORAGE ##
datadir=/var/lib/mysql

## InnoDB Configuration ##
innodb_file_per_table=1

# InnoDB Memory
innodb_buffer_pool_size = 2000M

# System Tablespace configuration
innodb_data_file_path= ibdata1:512M;ibdata2:512M:autoextend

# Redo log and buffer configuration
innodb-log-files-in-group=3
innodb_log_file_size=100M
innodb_log_buffer_size=30M

#InnoDB file formate
innodb_file_format = Barracuda

# UNDO Tablespace Configuration
innodb_undo_directory =  /var/lib/mysql/
innodb_undo_tablespaces = 3
innodb_undo_logs = 128
innodb_undo_log_truncate = ON
innodb_rollback_segments = 128

# Temp Tablespace Configuration
tmpdir = /var/lib/mysql/
innodb_temp_data_file_path = ibtmp1:20M:autoextend

# Keyring configuration
early-plugin-load=keyring_file.so
keyring_file_data=/var/lib/mysql-keyring/keyring

 

MySQL Server Initialization Logs:


[Note] InnoDB: Using Linux native AIO
[Note] InnoDB: Number of pools: 1
[Note] InnoDB: Using CPU crc32 instructions
[Note] InnoDB: Initializing buffer pool, total size = 2G, instances = 8, chunk size = 128M
[Note] InnoDB: Completed initialization of buffer pool
[Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
[Note] InnoDB: Opened 4 undo tablespaces
[Note] InnoDB: 4 undo tablespaces made active
[Note] InnoDB: Highest supported file format is Barracuda.
[Note] InnoDB: Creating shared tablespace for temporary tables
[Note] InnoDB: Setting file './ibtmp1' size to 20 MB. Physically writing the file full; Please wait ...
[Note] InnoDB: File './ibtmp1' size is now 20 MB.
[Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
[Note] InnoDB: 32 non-redo rollback segment(s) are active.
[Note] InnoDB: Waiting for purge to start
[Note] InnoDB: 5.7.19 started; log sequence number 2454162
[Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
[Note] Plugin 'FEDERATED' is disabled.
[Note] InnoDB: Buffer pool(s) load completed at 170828 12:03:52

UNDO and Temporary tablespaces:

mysql_datadir

General tablespace Example:

General Tablespace can be created inside mysql datadir [ Default ] or outside of the MySQL data directory.

Example:


# Create General tablespace
mysql> CREATE TABLESPACE gen_tblsp ADD DATAFILE 'gen_tlbsp.ibd' ENGINE = INNODB;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from INFORMATION_SCHEMA.FILES  where TABLESPACE_NAME ='gen_tblsp'\G
*************************** 1. row ***************************
             FILE_ID: 27
           FILE_NAME: ./gen_tlbsp.ibd
           FILE_TYPE: TABLESPACE
     TABLESPACE_NAME: gen_tblsp
     ....
     ....

# Create table inside general tablespace.
mysql> CREATE TABLE gen_ts_tbl (id int(11), c_desc varchar(100), c_comments text ) TABLESPACE gen_tblsp;
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO gen_ts_tbl values (1, 'test' , 'General tablespace testing');
Query OK, 1 row affected (0.01 sec)

mysql> select * from gen_ts_tbl;
+------+--------+----------------------------+
| id   | c_desc | c_comments                 |
+------+--------+----------------------------+
|    1 | test   | General tablespace testing |
+------+--------+----------------------------+
1 row in set (0.00 sec)

# Move Existing table into general tablespace.

mysql> create table innodb_table (id int (11), uname varchar(78));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into innodb_table values(1,'moving to gen_tblsp');
Query OK, 1 row affected (0.01 sec)

mysql> ALTER TABLE innodb_table TABLESPACE gen_tblsp;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> select * from innodb_table;
+------+---------------------+
| id   | uname               |
+------+---------------------+
|    1 | moving to gen_tblsp |
+------+---------------------+
1 row in set (0.00 sec)

# DROP General Tablespace [ We need to drop all table in general tablespace before dropping it]

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| gen_ts_tbl     |
| innodb_table   |
+----------------+
2 rows in set (0.00 sec)

mysql> drop table gen_ts_tbl;
Query OK, 0 rows affected (0.01 sec)
mysql> drop table innodb_table;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
Empty set (0.01 sec)

mysql> drop tablespace gen_tblsp;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from INFORMATION_SCHEMA.FILES  where TABLESPACE_NAME ='gen_tblsp'\G
Empty set (0.00 sec)

mysql_general_tablespace

InnoDB TDE using a keyring_file plugin:


mysql>  SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS
        WHERE PLUGIN_NAME LIKE 'keyring%';
+--------------+---------------+
| PLUGIN_NAME  | PLUGIN_STATUS |
+--------------+---------------+
| keyring_file | ACTIVE        |
+--------------+---------------+
1 row in set (0.00 sec)

mysql> show variables like '%keyring%';
+-------------------+--------------------------------+
| Variable_name     | Value                          |
+-------------------+--------------------------------+
| keyring_file_data | /var/lib/mysql-keyring/keyring |
+-------------------+--------------------------------+
1 row in set (0.00 sec)

 mysql> CREATE TABLE innodb_tde (id int(11), c_desc varchar(100), c_comments text ) ENCRYPTION='Y';
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT TABLE_SCHEMA, TABLE_NAME, CREATE_OPTIONS FROM
       INFORMATION_SCHEMA.TABLES WHERE CREATE_OPTIONS LIKE '%ENCRYPTION="Y"%';
+--------------+------------+----------------+
| TABLE_SCHEMA | TABLE_NAME | CREATE_OPTIONS |
+--------------+------------+----------------+
| test         | innodb_tde | ENCRYPTION="Y" |
+--------------+------------+----------------+
1 row in set (0.01 sec)

mysql> INSERT INTO innodb_tde values (1, 'test tde' , 'innodb tde testing');
Query OK, 1 row affected (0.00 sec)

mysql> select * from innodb_tde;
+------+----------+--------------------+
| id   | c_desc   | c_comments         |
+------+----------+--------------------+
|    1 | test tde | innodb tde testing |
+------+----------+--------------------+
1 row in set (0.01 sec)</pre>
# Disable - Enable ENCRYPTION from table

mysql> ALTER TABLE innodb_tde ENCRYPTION='N';
Query OK, 1 row affected (0.02 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> ALTER TABLE innodb_tde ENCRYPTION='Y';
Query OK, 1 row affected (0.02 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from innodb_tde;
+------+----------+--------------------+
| id | c_desc | c_comments |
+------+----------+--------------------+
| 1 | test tde | innodb tde testing |
+------+----------+--------------------+
1 row in set (0.00 sec)

#ENCRYPTION MASTER KEY Rotation

mysql> ALTER INSTANCE ROTATE INNODB MASTER KEY;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from innodb_tde;
+------+----------+--------------------+
| id | c_desc | c_comments |
+------+----------+--------------------+
| 1 | test tde | innodb tde testing |
+------+----------+--------------------+
1 row in set (0.00 sec)

Refer MySQL doc for more:
https://dev.mysql.com/doc/refman/5.7/en/innodb-tablespace.html

Advertisements

MySQL High Availability with Keepalived and HAProxy

In this blog post, we are going to test load balancer solution for MySQL high availability by integrating it with Keepalived, HAProxy, xinetd software components.

LB_diag

High availability databases use an architecture that is designed to continue to function normally even when there are hardware or network failures within the system.

Why we need this?

Let’s take a scenario where we have MySQL Multi-Master / MASTER-SLAVE replication setup for high availability. In the case of Hardware/Network failure on MASTER, In order to failover to a next available server, we need to manually do the configuration changes for client connections.In this case, downtime is expected since manual failover will take some times. To solve this we can integrate load balancer with MySQL to take care of this manual work and do automatic failover connections.

To avoid such downtimes and for the maximum high availability of the database, we can integrate load balancer with MySQL to take care of this manual work and do automatic failover connections.

Advantages:

  • Almost ZERO DOWNTIME for DB maintenance activities like database patching/upgrades, configuration changes that need DB restart etc.
  • Easy Read-Write load distribution.
  • Automatic Failover.
  • Easy to setup and manage.

Load Balancer is a set of integrated software components that provide for balancing IP traffic across a set of real servers. It consists of two main technologies to monitor cluster members and cluster services: Keepalived and HAProxy.

Keepalived: It uses Linux virtual server (LVS) to perform load balancing and failover tasks on.

HAProxy: It performs load balancing and high-availability services to TCP and HTTP applications.

xinetd: “Extended Internet daemon” is an open-source super-server daemon which runs on many Unix-like systems and manages Internet-based connectivity.xinetd runs constantly and listens on all ports for the services it manages. When a connection request arrives for one of its managed services, xinetd starts up the appropriate server for that service.

VIP:  Virtual IP addresses (or VIPs) allow you to use multiple IPs on a single physical network interface.

Keepalive Configuration:

Load Balancer #1 Configuration

global_defs {
   notification_email {
     mysql-user@mydomain.com
   }
   notification_email_from svr1@mydomain.com
   smtp_server localhost
   smtp_connect_timeout 30
}
vrrp_instance VRRP1 {
    state MASTER
#   Specify the network interface to which the virtual address is assigned
    interface eth0
#   The virtual router ID must be unique to each VRRP instance that you define
    virtual_router_id 71
#   Set the value of priority higher on the master server than on a backup server
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1066
    }
virtual_ipaddress {
192.168.2.111
192.168.2.112
}
}

Load Balancer #2 Configuration


global_defs {
   notification_email {
     mysql-user@mydomain.com
   }
   notification_email_from svr2@mydomain.com
   smtp_server localhost
   smtp_connect_timeout 30
}

vrrp_instance VRRP1 {
    state BACKUP
#   Specify the network interface to which the virtual address is assigned
    interface eth0
#   The virtual router ID must be unique to each VRRP instance that you define
    virtual_router_id 71
#   Set the value of priority higher on the master server than on a backup server
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1066
    }
virtual_ipaddress {
192.168.2.111
192.168.2.112
}
}

HAProxy Configuration on Load balancer #1 and #2 :


  global
        daemon
        maxconn 256

    defaults
        mode http
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms

# MYSQL Configuration 

listen write_connections 192.168.2.111:3306
mode tcp
balance roundrobin
option httpchk
server mysql_db1 192.168.2.105:3306 check port 9200
server mysql_db2 192.168.2.106:3306 check port 9200 backup 

listen read_connections 192.168.2.112:3306
mode tcp
balance leastconn
option httpchk
server mysql_db3 192.168.2.107:3306 check port 9200 

Note: Add all IP and hostname entries in /etc/hosts file.

xinetd configuration on all mysql server:

/etc/xinetd.d/mysqlchk

# default: on
# description: mysqlchk
service mysqlchk
{
flags = REUSE
socket_type = stream
port = 9200
wait = no
user = nobody
server = /opt/mysqlchk
log_on_failure += USERID
disable = no
only_from = 0.0.0.0/0
per_source = UNLIMITED

NOTE: Create following script on all mysql server to monitor mysql status.
mysqlchk.stauts script [/opt/mysqlchk.stauts] : The purpose of this script is make haproxy capable of monitoring mysql properly


# It is recommended that a low-privileged-mysql user is created to be used by
# this script. Something like this:
#mysql> CREATE USER IF NOT EXISTS 'mysqlchkuser'@'localhost' IDENTIFIED BY 'P@ssword#567';
# mysql> GRANT show databases on *.* TO 'mysqlchkuser'@'localhost';
# mysql> flush privileges;

MYSQL_HOST="localhost"
MYSQL_PORT="3306"
MYSQL_USERNAME="mysqlchkusr"
MYSQL_PASSWORD="P@ssword#567"

TMP_FILE="/opt/tmp/mysqlchk.out"
ERR_FILE="/opt/tmp/mysqlchk.err"

#
# We perform a simple query that should return a few results.
#
mysql --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USERNAME --password=$MYSQL_PASSWORD -e"show databases;" > $TMP_FILE 2> $ERR_FILE

#
# Check the output. If it is not empty then everything is fine and we return
# something. Else, we just do not return anything.
#
if [ "$(/bin/cat $TMP_FILE)" != "" ]
then
    # mysql is fine, return http 200
    /bin/echo -e "HTTP/1.1 200 OKrn"
    /bin/echo -e "Content-Type: Content-Type: text/plainrn"
    /bin/echo -e "rn"
    /bin/echo -e "MySQL is running.rn"
    /bin/echo -e "rn"
else
    # mysql is fine, return http 503
    /bin/echo -e "HTTP/1.1 503 Service Unavailablern"
    /bin/echo -e "Content-Type: Content-Type: text/plainrn"
    /bin/echo -e "rn"
    /bin/echo -e "MySQL is *down*.rn"
    /bin/echo -e "rn"
fi

Testing:

  • Test MySQL connection with VIP address.
  • Stop MySQL Active MASTER, and connect to MySQL.It should connect to backup MySQL server specified in HAProxy configuration.
  • Test Keepalived and HAProxy failover.

All Set!!

Basics of MySQL Administration and best practices

Following are the few best practices and basic commands for MySQL Administration.

MySQL Access and credential security

shell> mysql -u testuser -pMyP@ss0rd
mysql: [Warning] Using a password on the command line interface can be insecure.

By looking at OS cmd’s history using history cmd other os users can see/get MySQL user password easily. It always good to not use a password on the command line interface. Another option for securing password while automating MySQL scripts is a use of mysql_config_editor. For more info on this check out my blog post about credential security.

Consider of having following implementation for Strong access policy.

  • use of  validate_password plugin for a strong password policy.
  • Limit the user access by specifying IP or IP range in a hostname.
  • Do not grant accessive privileges to user/s.
  • Have separate users for different operations like backup user with required backup privileges only.
  • Avoid giving FILE and super privileges to remote users.
  • For public network communication between client and server use SSL connection method.

Replication

  •  IF EXISTS and IF NOT EXISTS use while creating DB objects.

Most common problem for replication break or errors is that OBJECT already exists on SLAVE. By using IF EXISTS and IF NOT EXISTS while creating database objects we can avoid.

  • Use of GTID and crash-safe replication.
  • Keep your slave in read-only mode.
  • Run your backups and query optimization on SLAVE. This will avoid unnecessary load on MASTER.

Logging

Logs are great significance for admin. Following types of logs, you can enable for MySQL servers.

  • Binary log: Extra copy of your database transactions.
  • Relay log:  By default enable and get created when you setup replication.
  • General log: To log MySQL client tool commands.
  • Slow query log: Log slow queries taking more time for execution.
  • Error / MySQL server log: Record NOTES, WARNINGS and ERROR for MySQL server.
  • Audit Log:  Log user info and activities like executes queries by a user/s along with source IP, timestamp, target database etc.
  • To maintain these logs like purging OLD logs using logrotate. Check MYSQL SERVER LOG MAINTENANCE for more info.

 MySQL STARTUP- SHUTDOWN

Always check MySQL error log for STARTUP- SHUTDOWN and make sure for clean STARTUP/ SHUTDOWN.

Basic commands for MySQL Administration

MySQL database and table creation

CREATE IF NOT EXISTS DATABASE:

CREATE IF NOT EXISTS  DATABASE test_db ;
Use test_db ;

CREATE TABLE:

CREATE IF NOT EXISTS TABLE t1 (id int(11) primary key auto_incremnet ,uname varchar(50), comments text);

INSERT INTO TABLE:

INSERT INTO t1 (id, uname, comments) VALUES(101,’lalit’,’mysql DBA’);

MySQL Database Users

CREATE USER:

  1. The CREATE USER statement creates new MySQL accounts.
CREATE USER IF NOT EXISTS 'local_user1'@'localhost' IDENTIFIED BY 'mypass'; (Remote connection restricted for this user)

If you specify only a username part of the account name, a host name part of ‘%’ is used.

CREATE USER IF NOT EXISTS 'remote_user1'@'%' IDENTIFIED BY 'mypass';

(Remote connection enabled for this user)

  1. User details are getting stored under user table.
SELECT user,host FROM mysql.user;

 

RENAME USER:

RENAME USER 'abc'@'localhost' TO 'xyz'@'%';

DROP USER:

 DROP IF EXISTS USER 'remote_user1'@'%’;

User password management:

  1. Change/Update user password.
ALETR USER IF EXISTS 'remote_user1'@'%' IDENTIFIED BY 'mypass';
  1. Password expire user account
ALTER USER IF EXISTS 'remote_user1'@'%' PASSWORD EXPIRE;
  1. Locked User account
ALTER USER IF EXISTS 'remote_user1'@'%' ACCOUNT LOCK;

 

MySQL Database Users Access Restrictions using privileges.

Grant privileges to a user:

Privileges can be granted on database/s, table/s and related objects to it.

Example.

Case1:  Grant all privileges on ‘db1’ database to user ‘remote_user1’@’%’

GRANT ALL PRIVILEGES ON db1.* TO 'remote_user1'@'%';

Case2: Grant selected privileges on ‘db1’ database to user ‘remote_user1’@’%’

GRANT SELECT, INSERT, UPDATE, DELETE ON db1.* TO 'remote_user1'@'%';

Case3. Grant SELECT privilege single table access to user ‘remote_user1’@’%’

GRANT SELECT ON db1.table1 TO 'remote_user1'@'%';

Ref: http://dev.mysql.com/doc/refman/5.7/en/grant.html

Revoking privileges from user:

Example:

REVOKE SELECT, INSERT, UPDATE, DELETE ON db1.* FROM 'remote_user1'@'%';

Ref: http://dev.mysql.com/doc/refman/5.7/en/revoke.html

Check User Privileges using SHOW GRANTS command:

Example:

SHOW GRANTS FOR 'mysqldba'@'localhost';

SHOW GRANTS; (It will display the privileges granted to the current account)

SHOW GRANTS FOR 'remote_user1'@'%';

Ref: http://dev.mysql.com/doc/refman/5.7/en/show-grants.html

MySQL monitoring

Check database size:

Information_schema (Metadata)

SELECT table_schema "Data Base Name",    sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",    sum( data_free )/ 1024 / 1024 "Free Space in MB"FROM information_schema.TABLESGROUP BY table_schema ;

Check Active users:

show processlist ;

InnoDB Engine Status:

SHOW STATUS;

SHOW ENGINE INNODB STATUS;
  1. Performance schema: Live statistics

Example:

– Enable Locking related instruments (if it’s not enabled):

UPDATE performance_schema.setup_instruments SET ENABLED=’YES’, TIMED=’YES’ WHERE NAME=’wait/lock/metadata/sql/mdl’;

SELECT * FROM performance_schema.metadata_locks WHERE OBJECT_SCHEMA=’test’ AND OBJECT_NAME LIKE ‘t_’;

  1. MySQL Enterprise monitor
  2. Customized scripts

Check Database objects info:

Databases:

SHOW DATABASES;

Select Database:

Use db_name;

Tables in Database:

SHOW TABLES;

SELECT TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = 'test_db';

ROUTINES:

select * from ROUTINES where ROUTINE_SCHEMA='db_name’;

INDEX:

select TABLE_NAME,INDEX_NAME,COLUMN_NAME,INDEX_TYPE  from information_schema.STATISTICS where TABLE_SCHEMA = 'db_name';

View:

select * from information_schema.VIEWS where TABLE_SCHEMA = 'db_name';

Mysqldump  Backup-Restore:

Require privileges: mysqldump requires at least the SELECT privilege for dumped tables, SHOW VIEW for dumped views, TRIGGER for dumped triggers, and LOCK TABLES if the –single-transaction option is not used. Certain options might require other privileges as noted in the option descriptions.

Backup:

Full Database backup:

mysqldump -u root  -p --single-transaction --databases db1  --routines > db1_fullbkp.sql

 OR

mysqldump -u root  -p --single-transaction  --databases db1 --routines | gzip >  db1_fullbkp.sql.gz

 

Single table backup:

mysqldump -u  -h  -p --single-transaction db_name table_name --routines > db1_full.sql

Ref : http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html

Restore:

To reload a dump file, you must have the privileges required to execute the statements that it contains, such as the appropriate CREATE privileges for objects created by those statements.

mysql -u username -p db_name < db1_fullbkp.sql

OR

gunzip < db1_fullbkp.sql.gz | mysql -u username -p db_name

MySQL Replication:

  1. Create replication user on MASTER with replication privileges.
CREATE USER [IF NOT EXISTS] 'rpluser'@'%' IDENTIFIED BY 'rpluser1234';GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'rpluser'@'%';
  1. On SLAVE: setup replication as follows:
CHANGE MASTER TO MASTER_HOST='<MASTER_IP',MASTER_USER='rpluser',MASTER_PASSWORD='rpluser1234',MASTER_PORT=3306,MASTER_AUTO_POSITION=1;
  1. Start slave
START SLAVE;
  1. Check slave status
SHOW SLAVE STATUS;

Slave_IO_Running and Slave_SQL_Running column value should be ‘YES’

MYSQL service [Linux]

MySQL SHUTDOWN steps:

shell> sudo service mysqld stop

MySQL STARTUP steps:

shell> sudo service mysqld start

All Set !!

MySQL Server log Maintenance

As a part database administration, DBA has to take care of sub-components of database like server logs and has to plan for maintenance activity for these components regularly.

MySQL has various types of log i.e binary log, error log, slow query log, general log for different purposes. And after certain time these logs will grow and you will start seeing issues like low disk space, a large number of logs etc.

MySQL allows you to flush logs using flush logs command, next “How to rotate and clean up old MySQL logs? ”

Linux has a utility called “logrotate” , using logrotate we can implement log rotation for MySQL server logs.

Binary logs: This one is critical if you have replication setup, By enabling  expire_logs_days mysql variable you can manage cleanup and flush logs cmd will rotate binary log.

For General and Slow query that’s not the case, “flush log” cmd will flush the content from memory to respective log files, but it will not rotate these logs. logrotate by default configured and managed with OS root user.On a Linux (Red Hat) installation, you can use the mysql-log-rotate script for this. If you installed MySQL from an RPM distribution, this script should have been installed automatically. It kind of sample script for full implementation, let’s create a separate mysql-log-rotate script.

Prerequisites:

USER and Privileges:

CREATE USER  'logadmin'@'localhost' IDENTIFIED BY 'xyzpwd';
GRANT RELOAD ON *.* TO 'logadmin'@'localhost';

Secure user credentials using mysql_config_editor:

shell> mysql_config_editor set --login-path=logadmin_client --host=localhost --user=monitor --password                                                                                     

Enter password:<enter_mysql_logadmin_user_password>

NOTE: It will store user credentials info into .mylogin.cnf (This conf file will be get created under current OS user home directory)

mysql-log-rotate script

/PATH/log/mysqld.log /PATH/log/slow-query.log /PATH/log/general-query.log {
create 640 mysql mysql
rotate 5
daily
minsize 1M
notifempty
missingok
compress
postrotate
# just if mysqld is really running
if test -x /usr/bin/mysqladmin
/usr/bin/mysqladmin --login-path=logadmin_client ping >/dev/null
then
/usr/bin/mysqladmin --login-path=logadmin_client flush-logs
fi
endscript
}

NOTE: Above script will flush logs 3 times since we have 3 logs in one code block.To flush log only at once you can create separate rotate code block for each log and add postrotate script only in the last rotation code block.

Automation:

00 03 * * * /usr/sbin/logrotate -s /PATH/log/logrotate.status /PATH/monitor/mysql-log-rotate.sh > /PATH/log/logrotate_cron.log 2>&1

Key points:

  • You can set rotation on the basis of SIZE, TIME or both. Explore logrotate option for more options.
  • -s /PATH/log/logrotate.status file will get create/update with log name and timestamp, Which will get use for next rotation on the basis of filename and timestamp it has.
  • -f, --force
    Tells logrotate to force the rotation, even if it doesn’t think
    this is necessary. Sometimes this is useful after adding new
    entries to logrotate, or if old log files have been removed by
    hand, as the new files will be created, and logging will continue correctly.

All Set !!

MSSQL to MySQL Data migration using MySQL workbench 6.3

Recently I was testing data migration from MSSQL to MySQL using MySQL Workbench. My aim was to include data with all datatype available in MSSQL for migration. In this following blog post will see data migration prerequisites, migration steps and few common errors.

About MySQL Workbench

MySQL Workbench is a unified visual tool for database architects, developers, and DBAs. MySQL Workbench provides data modeling, SQL development, and comprehensive administration tools for server configuration, user administration, backup, Data migration and much more. MySQL Workbench is available on Windows, Linux and Mac OS X.

When a supported RDBMS product is being migrated, the MySQL Workbench Migration Wizard will automatically convert as much information as it can, but you may still be required to manually edit the automatically migrated schema for difficult cases, or when the default mapping is not as desired.

Generally speaking, only table information and its data are automatically converted to MySQL. Code objects such as views, stored procedures, and triggers, are not. But supported RDBMS products will be retrieved and displayed in the wizard. You can then manually convert them, or save them for converting at a later time.

The following MS-SQL versions are currently tested and supported by the MySQL Workbench Migration Wizard.

Microsoft SQL Server 2000, 2005, 2008, 2012

Prerequisite

Download and install MySQL Workbench GUI tool.

The MySQL Workbench Migration Wizard uses ODBC to connect to a source database, except for MySQL. You will need the ODBC driver installed that corresponds to the database you want to migrate from.

Preparation

To be able to migrate from Microsoft SQL Server, ensure the following:

  • The source SQL Server instance is running, and accepts TCP connections.
  • You know the IP and port of the source SQL server instance. If you will be migrating using a Microsoft ODBC driver for SQL Server (the default in Windows), you will need to know the host and the name of the SQL Server instance.
  • Make sure that the SQL Server is reachable from where you will be running MySQL Workbench. More specifically, check the firewall settings.
  • Make sure that the user account has proper privileges to the database that will be migrated.

DATA SOURCE ODBC Configuration

In order to set up a connectivity between MSSQL and MySQL, We need to configure DATA SOURCE drivers ODBC with MS-SQL connection information.

Add new System data source.

odbc_pic

Required privileges on MS-SQL DB

CONNECT SQL

VIEW ANY DATABASE

VIEW ANY DEFINITION

If proper permission not given then at the migration it will throw warning as follow,

blog_lalit_pic2

DB Servers Data Types Mapping

Refer:

https://dev.mysql.com/doc/workbench/en/wb-migration-database-mssql-typemapping.html

Available datatype in MS-SQL:

https://msdn.microsoft.com/en-us/library/ms187752.aspx

Sample MS-SQL data

Sample table and data with different MS-SQL datatype

-- integer data types

CREATE TABLE dbo.int_table
(
MyBigIntColumn bigint
,MyIntColumn  int
,MySmallIntColumn smallint
,MyTinyIntColumn tinyint
);

ALter table int_table add MyBitColumn bit;

ALter table int_table add CONSTRAINT bit_def default 1  for MyBitColumn;

INSERT INTO dbo.int_table VALUES (9223372036854775807, 214483647,32767,255);

update int_table SET MyBitColumn=1;

Alter table int_table alter column MyBitColumn bit not null;

-- decimal and numeric Data datatypes

CREATE TABLE dbo.num_table
(
MyDecimalColumn decimal(5,2)
,MyNumericColumn numeric(10,5)
);

INSERT INTO dbo.num_table VALUES (123, 12345.12);

Alter table num_table add MyMoneycolumn money;

Alter table num_table add MysmallMoneycolumn smallmoney;

INSERT INTO num_table (MyMoneyColumn,MysmallMoneycolumn) values(20.098,45.68);

alter table num_table add c_real real,c_float float (32);

INSERT INTO num_table (c_real,c_float) values(2.0,43.67897);

-- datetime datatype

create table date_table(
ID               VARCHAR(4)         NOT NULL,
First_Name         VARCHAR(20),
Last_Name          VARCHAR(20),
Start_Date         DATE,
End_Date           DATE,
c_time             Time,
Salary             Money,
City               VARCHAR(20),
Description        VARCHAR(80),
c_datetime             datetime,
cs_smalldatetime    smalldatetime,
c_datetime2         datetime2
)

ALTER TABLE date_table ADD CONSTRAINT cc_datetime DEFAULT GETDATE() FOR c_datetime;

ALTER TABLE date_table ADD CONSTRAINT cc_time DEFAULT convert(time, getdate()) FOR c_time;

ALTER TABLE date_table ADD CONSTRAINT cc_startdate DEFAULT convert(date,getdate()) FOR start_date;

ALTER TABLE date_table ADD CONSTRAINT cc_enddate DEFAULT convert(date,getdate()) FOR end_date;

-- prepare data

insert into date_table(ID,  First_Name, Last_Name,Salary,  City, Description,cs_smalldatetime,c_datetime2)

values ('01','Jason',    'Martin', 1234.56, 'Toronto',  'Programmer','2007-05-08 12:35:00','2007-05-08 12:35:29. 1234567');

insert into date_table(ID,  First_Name, Last_Name,Salary,  City, Description,cs_smalldatetime,c_datetime2)

values('02','Alison',   'Mathews', 2234.78, 'Vancouver','Tester','2016-07-08 12:36:00','2006-07-08 12:36:29. 1234567'); 

-- char,varchar,nvarchar,tinyint,int,text datatypes

CREATE TABLE [dbo].[Employee_2](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](150) NULL,
[empid] [int] NOT NULL,
[age] [tinyint] NOT NULL,
[gender] VARCHAR(10) NOT NULL CHECK (gender IN('male', 'Female', 'Unknown'))
);

Alter table Employee_2 add primary key (Id);

-- Create a nonclustered index on a table or view

CREATE INDEX i1 ON dbo.Employee_2 (Name);

--Create a clustered index on a table and use a 3-part name for the table

CREATE CLUSTERED INDEX ci1 ON Employee_2([Id]);

CREATE UNIQUE INDEX pk1 ON dbo.Employee_2 (Id);

-- Create a nonclustered index with a unique constraint on 3 columns and specify the sort order for each column

CREATE UNIQUE INDEX ui1 ON dbo.Employee_2 (name DESC, empid ASC, age DESC);

INSERT INTO Employee_2 (Name,empid,age,gender) values ('lalit',268981,27,'male');

INSERT INTO Employee_2 (Name,empid,age,gender) values ('harsh',268982,28,'male');

INSERT INTO Employee_2 (Name,empid,age,gender) values ('jina',268983,27,'female');

INSERT INTO Employee_2 (Name,empid,age,gender) values ('xyz',268984,32,'Unknown');

ALTER table employee_2 add emp_notes2 text;

update employee_2 SET emp_notes2='test data Migration from mssql- mysql';

CREATE TABLE Persons
(
P_Id int NOT NULL,
Lastname varchar(40),
Firstname varchar(40) NOT NULL,
Address varchar(100),
City char(50),
PRIMARY KEY (P_Id)
);

INSERT INTO Persons values(1,'c','lalit','IT park','PUNE');

CREATE TABLE Orders
(
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
PRIMARY KEY (O_Id),
CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)
);

INsert INTO orders values(1,2234,1);

create table binary_table (c_binary binary , c_varbinary varbinary (max) ,c_image image);

INSERT INTO binary_table (c_varbinary)
values (convert(VARBINARY(max),44));

Few extra tables MS-SQL Table:

  1. [dbo].[Altiris, Inc_$Item] table with 20686 rows
CREATE TABLE [dbo].[Altiris, Inc_$Item](
[No_] [varchar](20) NOT NULL,
[Description] [varchar](100) NOT NULL,
[Description 2] [varchar](50) NULL,
[Blocked] [tinyint] NOT NULL,
[Last Date Modified] [datetime] NULL,
[Inactive] [tinyint] NOT NULL,
[Fixed Node] [tinyint] NOT NULL,
[Minimum Nodes] [int] NOT NULL,
[Maximum Nodes] [int] NOT NULL,
[Tax Group Code] [varchar](10) NOT NULL,
[Current Price List] [tinyint] NOT NULL,
[PrimeKey] [int] IDENTITY(1,1) NOT NULL,
CONSTRAINT [primeKey_FK1] PRIMARY KEY CLUSTERED
(
[PrimeKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

  1. [dbo].[Employee]
CREATE TABLE [dbo].[Employee](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](150) NULL,
CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

  1. [dbo].[CUSTOMERS]
CREATE TABLE [dbo].[CUSTOMERS](
[ID] [int] NOT NULL,
[NAME] [varchar](20) NOT NULL,
[AGE] [int] NOT NULL,
[ADDRESS] [char](25) NULL,
[SALARY] [decimal](18, 2) NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

 
  1. [dbo].[Products]
CREATE TABLE [dbo].[Products](
[ProductID] [int] NOT NULL,
[ProductName] [varchar](25) NOT NULL,
[Price] [money] NULL,
[ProductDescription] [text] NULL,
[c_time] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED
(
[ProductID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Products] ADD  CONSTRAINT [DF_YourTable]  DEFAULT (getdate()) FOR [c_time]
GO

Note: Insert appropriate data in above tables for respective datatypes.

Migration using MySQL Workbench

mig1

MS-SQL Connection test:
mig2

NOTE:  Connection method ‘ODBC Data Source’ option will cause for following error. To avoid such error at the time of data migration use Connection method as ‘ODBC Data Source [FreeTDS]

mig3

MySQL Connection test:
mig4

Fetching schema:
mig5

Schema selection and DB naming settings:
mig6

Reverse Engineering:
mig7

Source object list:
mig9

Migration:
mig10

Manual editing: ( If needed)
mig11

NOTE: Will Fix these warnings in next steps.

Target creation options:
mig12

Create schemas:
mig13

Create target result:
mig14

As we have seen warnings for date_table as ‘Defaults value CONVERT(……) is not supported’. In MySQL we cannot use functions in with default, to tackle this problem will create trigger on table for insert operation as follows,

CREATE TRIGGER before_insert_date_table
before INSERT ON date_table
FOR EACH ROW
SET new.Start_Date = curdate() , new.End_Date= curdate() , new.c_time= curtime();

The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for TIMESTAMP and DATETIME columns.

https://dev.mysql.com/doc/refman/5.7/en/data-type-defaults.html

Another table that we need to fix is  Employee_2

MS-SQL Employee_2 table column definition:

[gender] VARCHAR(10) NOT NULL CHECK (gender IN('male', 'Female', 'Unknown'))

MySQL Employee_2 table column definition:
mig15

Appropriate datatype for ‘gender’ column, Let change it:

`gender` enum('Male','Female','Unknown') NOT NULL default 'Unknown',

Data transfer setup:
mig16

Bulk data transfer:
mig17

Data and Log analysis

Migration Report:

------------------------------------------------------------------------------------

MySQL Workbench Migration Wizard Report

Source: Microsoft SQL Server 12.0.4100

Target: MySQL 5.7.15

------------------------------------------------------------------------------------
-- Migration

-- Summary


Number of migrated schemas: 1

-- mysql_migration

Source Schema:   mysql_migration

- Tables:             11
- Triggers:           0
- Views:              4
- Stored Procedures:  3
- Functions:          0


2. Migration Issues
  - mysql_migration
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - CUSTOMERS
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - NAME
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - ADDRESS
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Products
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - ProductName
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - ProductDescription
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - c_time
    note  Default value is getdate(), so type was changed from DATETIME to TIMESTAMP
  - Employee
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Name
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Employee_2
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Name
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - gender
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - emp_notes
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - emp_notes2
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Persons
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Lastname
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Firstname
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Address
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - City
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Orders
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - int_table
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - MyBitColumn
    note  Source column type BIT was migrated to TINYINT(1)
  - num_table
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - date_table
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - ID
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - First_Name
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Last_Name
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Start_Date
    warning  Default value CONVERT([date],getdate(),0) is not supported
  - End_Date
    warning  Default value CONVERT([date],getdate(),0) is not supported
  - c_time
    warning  Default value CONVERT([time],getdate(),0) is not supported
  - City
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Description
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - c_datetime
    note  Default value is getdate(), so type was changed from DATETIME to TIMESTAMP
  - binary_table
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Altiris, Inc_$Item
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - No_
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Description
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Description 2
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci
  - Tax Group Code
    note  Collation SQL_Latin1_General_CP1_CI_AS migrated to utf8_general_ci


3. Object Creation Issues


4. Migration Details

4.1. Table mysql_migration.CUSTOMERS (CUSTOMERS)

Columns:
  - ID INT    
  - NAME VARCHAR(20)    
  - AGE INT    
  - ADDRESS CHAR(25)    
  - SALARY DECIMAL(18,2)    

Foreign Keys:

Indices:
  - PRIMARY (ID)


4.2. Table mysql_migration.Products (Products)

Columns:
  - ProductID INT    
  - ProductName VARCHAR(25)    
  - Price DECIMAL(19,4)    
  - ProductDescription LONGTEXT    
  - c_time TIMESTAMP  CURRENT_TIMESTAMP  

Foreign Keys:

Indices:
  - PRIMARY (ProductID)


4.3. Table mysql_migration.Employee (Employee)

Columns:
  - Id INT    
  - Name VARCHAR(150)    

Foreign Keys:

Indices:
  - PRIMARY (Id)


4.4. Table mysql_migration.Employee_2 (Employee_2)

Columns:
  - Id INT    
  - Name VARCHAR(150)    
  - empid INT    
  - age TINYINT UNSIGNED   
  - gender VARCHAR(10)    
  - emp_notes LONGTEXT    
  - emp_notes2 LONGTEXT    

Foreign Keys:

Indices:
  - PRIMARY (Id)
  - ci1 (Id)
  - i1 (Name)
  - pk1 (Id)
  - ui1 (Name, empid, age)


4.5. Table mysql_migration.Persons (Persons)

Columns:
  - P_Id INT    
  - Lastname VARCHAR(40)    
  - Firstname VARCHAR(40)    
  - Address VARCHAR(100)    
  - City CHAR(50)    

Foreign Keys:

Indices:
  - PRIMARY (P_Id)


4.6. Table mysql_migration.Orders (Orders)

Columns:
  - O_Id INT    
  - OrderNo INT    
  - P_Id INT    

Foreign Keys:
  - fk_PerOrders (P_Id) ON Persons (P_Id)

Indices:
  - PRIMARY (O_Id)


4.7. Table mysql_migration.int_table (int_table)

Columns:
  - MyBigIntColumn BIGINT    
  - MyIntColumn INT    
  - MySmallIntColumn SMALLINT    
  - MyTinyIntColumn TINYINT UNSIGNED   
  - MyBitColumn TINYINT(1)  1  

Foreign Keys:

Indices:


4.8. Table mysql_migration.num_table (num_table)

Columns:
  - MyDecimalColumn DECIMAL(5,2)    
  - MyNumericColumn DECIMAL(10,5)    
  - MyMoneycolumn DECIMAL(19,4)    
  - MysmallMoneycolumn DECIMAL(10,4)    
  - c_real FLOAT(24,0)    
  - c_float DOUBLE    

Foreign Keys:

Indices:


4.9. Table mysql_migration.date_table (date_table)

Columns:
  - ID VARCHAR(4)    
  - First_Name VARCHAR(20)    
  - Last_Name VARCHAR(20)    
  - Start_Date DATE    
  - End_Date DATE    
  - c_time TIME(6)    
  - Salary DECIMAL(19,4)    
  - City VARCHAR(20)    
  - Description VARCHAR(80)    
  - c_datetime TIMESTAMP  CURRENT_TIMESTAMP  
  - cs_smalldatetime DATETIME    
  - c_datetime2 DATETIME(6)    

Foreign Keys:

Indices:


4.10. Table mysql_migration.binary_table (binary_table)

Columns:
  - c_binary BINARY(1)    
  - c_varbinary LONGBLOB    
  - c_image LONGBLOB    

Foreign Keys:

Indices:


4.11. Table mysql_migration.Altiris, Inc_$Item (Altiris, Inc_$Item)

Columns:
  - No_ VARCHAR(20)    
  - Description VARCHAR(100)    
  - Description 2 VARCHAR(50)    
  - Blocked TINYINT UNSIGNED   
  - Last Date Modified DATETIME(6)    
  - Inactive TINYINT UNSIGNED   
  - Fixed Node TINYINT UNSIGNED   
  - Minimum Nodes INT    
  - Maximum Nodes INT    
  - Tax Group Code VARCHAR(10)    
  - Current Price List TINYINT UNSIGNED   
  - PrimeKey INT    

Foreign Keys:

Indices:
  - PRIMARY (PrimeKey)


II. Data Copy

  - `mysql_migration`.`Employee`
            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[Employee]            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[Employee]            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[Employee]            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[Employee]    
  - `mysql_migration`.`binary_table`
            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[binary_table]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[binary_table]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[binary_table]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[binary_table]    
  - `mysql_migration`.`num_table`
            Succeeded : copied 4 of 4 rows from [mysql_migration].[dbo].[num_table]            Succeeded : copied 4 of 4 rows from [mysql_migration].[dbo].[num_table]            Succeeded : copied 4 of 4 rows from [mysql_migration].[dbo].[num_table]            Succeeded : copied 4 of 4 rows from [mysql_migration].[dbo].[num_table]    
  - `mysql_migration`.`Products`
          error  `mysql_migration`.`Products`:malloc(1073741824) failed for blob transfer buffer          error  `mysql_migration`.`Products`:Failed copying 2 rows          error  `mysql_migration`.`Products`:malloc(1073741824) failed for blob transfer buffer          error  `mysql_migration`.`Products`:Failed copying 2 rows            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[Products]            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[Products]    
  - `mysql_migration`.`int_table`
            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[int_table]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[int_table]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[int_table]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[int_table]    
  - `mysql_migration`.`Orders`
            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[Orders]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[Orders]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[Orders]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[Orders]    
  - `mysql_migration`.`Employee_2`
            Succeeded : copied 4 of 4 rows from [mysql_migration].[dbo].[Employee_2]            Succeeded : copied 4 of 4 rows from [mysql_migration].[dbo].[Employee_2]            Succeeded : copied 4 of 4 rows from [mysql_migration].[dbo].[Employee_2]            Succeeded : copied 4 of 4 rows from [mysql_migration].[dbo].[Employee_2]    
  - `mysql_migration`.`CUSTOMERS`
            Succeeded : copied 6 of 6 rows from [mysql_migration].[dbo].[CUSTOMERS]            Succeeded : copied 6 of 6 rows from [mysql_migration].[dbo].[CUSTOMERS]            Succeeded : copied 6 of 6 rows from [mysql_migration].[dbo].[CUSTOMERS]            Succeeded : copied 6 of 6 rows from [mysql_migration].[dbo].[CUSTOMERS]    
  - `mysql_migration`.`date_table`
            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[date_table]            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[date_table]            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[date_table]            Succeeded : copied 2 of 2 rows from [mysql_migration].[dbo].[date_table]    
  - `mysql_migration`.`Persons`
            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[Persons]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[Persons]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[Persons]            Succeeded : copied 1 of 1 rows from [mysql_migration].[dbo].[Persons]    
  - `mysql_migration`.`Altiris, Inc_$Item`
            Succeeded : copied 20686 of 20686 rows from [mysql_migration].[dbo].[Altiris, Inc_$Item]

Validate data in MySQL database and All set !!