Simple MSSQL Server to MySQL table converter using PHP CLI.
Make sure you have PHP mssql extension and PHP mysql extension extensions installed.
sudo apt-get install php5-mssql php5-mysql
sudo yum install php5-mssql php5-mysql
brew install php5-mssql php5-mysql
Edit the MSSQL and MySQL hostname, user, password, and database section. Run the script from command line using PHP CLI.
Edit the file mssql2mysql.php
using your favourite editor.
Change MSSQL
and MYSQL
variables:
/*
* SOURCE: MS SQL
*/
define('MSSQL_HOST','mssql_host');
define('MSSQL_USER','mssql_user');
define('MSSQL_PASSWORD','mssql_password');
define('MSSQL_DATABASE','mssql_database');
/*
* DESTINATION: MySQL
*/
define('MYSQL_HOST', 'mysql_host');
define('MYSQL_USER', 'mysql_user');
define('MYSQL_PASSWORD','mysql_password');
define('MYSQL_DATABASE','mysql_database');
Run the php script (make sure php is accessible in the path or environment variables)
php mssql2mysql.php
Sometimes you will get an error like:
PHP Warning: mssql_query(): message:
Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library
(such as ISQL) or ODBC version 3.7 or earlier. (severity 16) in ... on line 181
The easiest fix for users on unix systems would be to configure freetds
. Make sure the version is 7.0
not 4.2
:
sudo vim /etc/freetds/freetds.conf
[global]
# TDS protocol version
tds version = 7.0
Extra Info for non-unix OS: PHP Docs and StackOverflow