mySQL function behaves differently on 2 servers which are essentially the same - mysql

Allright, here is a hard one...
I have a development server with mySQL 5.1.73 on which I wrote a function to normalize a string for searching purposes.
When moving the function to the production environment, same mySQL version, same major OS version (CentOS 6.5) newest patches, same major kernel version etc. The function stopped working.
Here is the function
CREATE DEFINER=`user`#`%` FUNCTION `normalize`(str VARCHAR(255)) RETURNS varchar(255) CHARSET utf8
BEGIN
DECLARE normstring VARCHAR(255);
DECLARE i INT;
SET i = 0;
SET normstring = '';
SET str = lower(str);
loop1: WHILE i < length(str) DO
CASE substring(str,i,1)
WHEN 'ä' THEN SET normstring = concat(normstring,'ae');
WHEN 'ö' THEN SET normstring = concat(normstring,'oe');
WHEN 'ü' THEN SET normstring = concat(normstring,'ue');
WHEN 'ß' THEN SET normstring = concat(normstring,'ss');
WHEN '/' THEN SET i = i + 1; ITERATE loop1;
WHEN '.' THEN SET i = i + 1; ITERATE loop1;
WHEN '-' THEN SET i = i + 1; ITERATE loop1;
WHEN '(' THEN SET i = i + 1; ITERATE loop1;
WHEN ')' THEN SET i = i + 1; ITERATE loop1;
WHEN ' ' THEN SET i = i + 1; ITERATE loop1;
WHEN '\'' THEN SET i = i + 1; ITERATE loop1;
WHEN '\\' THEN SET i = i + 1; ITERATE loop1;
ELSE SET normstring = concat(normstring,substring(str,i,1));
END CASE;
SET i = i + 1;
END WHILE;
RETURN normstring;
END$$
DELIMITER ;
On the development server this converts 'Mönßtär' to 'moensstaer', but on the production server it converts it to 'mönßtä'
Changing
SET i = 0; and WHILE i < length(str)
to
SET i = 1; and WHILE i <= length(str)
corrects the missing last character, so the result is 'mönßtär' but one server should not start counting with 0 the other one with 1, right?
And the production server leaves all special characters untouched.
I have compared all global variables, not only those explicitly set in my.cnf, and except timezone, password and symlink setings they are equal (yes I should correct those differences, but that should have nothing to do with my problem, right?)
Are there some compile-settings which can influence this behaviour, or some external libraries that mySQL uses?
I'll probably have to find a workaround for the problem - I plan to normalize in the application rather than the database - the function is too slow in large queries anyway - but it would have been nice to convert the existing data in the database. But I'm really curious as to what causes such strange behaviour.
Character-Set settings on both servers (from the running environment):
character_set_client........................ utf8
character_set_connection.................... utf8
character_set_database...................... utf8
character_set_filesystem.................... binary
character_set_results....................... utf8
character_set_server........................ utf8
character_set_system........................ utf8
collation_connection........................ utf8_unicode_ci
collation_database.......................... utf8_unicode_ci
collation_server............................ utf8_unicode_ci

I believe you have different character set between your local environment and production. Look into these articles on how to detect How do I find out the default server character set in mysql? and how to change Change server variable character_set_server.

Related

Convert characters in string to numeric fixed positions ,2|4|6| needs to be ,020406

I have many files that need to be altered in order to import into cpanel, mysql. The number pattern is layout out like ,2|5|7|31|37|43|5
To import the file into the correct field, the data needs to be in format of 02050731374305
Is it better to just use notepad++ and edit all the files or is there a better way to import this data? Mysql field only allows numeric and is limited to 14 digits on this particular file.
The files I have are pretty much alike but vary in length. There are only 2 columns total in the file to import into mysql, cpanel.
reg expression might work but I have been finding errors on the replacement as it is picking up other numbers in the row and changing the data.
Here's a quick solution using awk:
echo "2|5|7|31|37|43|5" | awk -F'|' '{printf("%02d%02d%02d%02d%02d%02d%02d\n", $1, $2, $3, $4, $5, $6, $7)}'
02050731374305
as I a said a fucntion, that breaks the string and build the new one, will help you
DELIMITER //
CREATE DEFINER=`root`#`localhost` FUNCTION `new_function`(fullstr TEXT, delim char(1)) RETURNS char(16) CHARSET utf8mb4
DETERMINISTIC
BEGIN
DECLARE inipos INTEGER;
DECLARE endpos INTEGER;
DECLARE maxlen INTEGER;
DECLARE item VARCHAR(100);
SET inipos = 1;
SET #temptxt = '';
SET fullstr = CONCAT(fullstr,delim);
SET maxlen = LENGTH(fullstr) ;
REPEAT
SET endpos = LOCATE(delim, fullstr, inipos);
SET item = SUBSTR(fullstr, inipos, endpos - inipos);
IF item <> '' AND item IS NOT NULL THEN
SET #temptxt = CONCAT(#temptxt,LPAD(item,2,'0'));
END IF;
SET inipos = endpos + 1;
UNTIL inipos >= maxlen END REPEAT;
RETURN #temptxt;
END/7
DELIMITER ;
So you can
SELECT new_function('2|5|7|31|37|43|5','|')
And get
02050731374305
This can easily be done with Notepad++, using the power of lookaround.
This will add a zero before each digit alone and it works for any number of values:
Ctrl+H
Find what: (?<!\d)(?=\d(?!\d))
Replace with: 0
CHECK Wrap around
CHECK Regular expression
Replace all
Explanation:
(?<! # negative lookbehind, make sure we haven't before:
\d # a digit
) # end lookbehind
(?= # positive lookahead, make sure we have after:
\d # digit
(?!\d) # not followed by another digit
) # end lookahead
Screenshot (before):
Screenshot (after):

How to use DELIMITER in mariadb using the .NET MySql connector?

I'm using MariaDB 10.2.12 and connecting using the .NET MySQL connector. The following trigger works fine in MySQL Workbench:
DELIMITER //
CREATE TRIGGER update_last_modified
BEFORE UPDATE ON users
FOR EACH ROW
BEGIN
DECLARE miscdataWithDate JSON;
IF JSON_CONTAINS_PATH(NEW.miscdata, 'all', '$.v1.lastModified2') THEN
SET NEW.miscdata = JSON_REPLACE(NEW.miscdata, '$.v1.lastModified2', UTC_TIMESTAMP());
ELSE
SET miscdataWithDate = JSON_SET('{"v1": {}}', '$.v1.lastModified2', UTC_TIMESTAMP());
SET NEW.miscdata = JSON_MERGE(NEW.miscdata, miscdataWithDate);
END IF;
END; //
DELIMITER ;
To run the command from C#/.NET, I used the following. I tried it with and without the final semicolon, in case the library is adding a semicolon:
using (var cmd = new MySqlCommand(#"CREATE TRIGGER update_last_modified
BEFORE INSERT ON users
FOR EACH ROW
BEGIN
DECLARE miscdataWithDate JSON;
IF JSON_CONTAINS_PATH(NEW.miscdata, 'all', '$.v1.lastModified') THEN
SET NEW.miscdata = JSON_REPLACE(NEW.miscdata, '$.v1.lastModified', UTC_TIMESTAMP());
ELSE
SET miscdataWithDate = JSON_SET('{""v1"": {}}', '$.v1.lastModified', UTC_TIMESTAMP());
SET NEW.miscdata = JSON_MERGE(NEW.miscdata, miscdataWithDate);
END IF;
END; //
DELIMITER ;", connection))
{
await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
}
When the trigger is defined (not called), the error is:
Unhandled Exception: System.AggregateException: One or more errors occurred. (You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '//
DELIMITER' at line 1) ---> MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '//
DELIMITER' at line 1
If I simplify the query so it doesn't need DELIMITER set, it works. But even a very simple trigger with a custom delimiter fails.
When searching for how other people have successfully used delimiters with MySQL/MariaDB from .NET, I found the following article: https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-mysqlscript-delimiter.html
The example given uses MySqlScript instead of MySqlCommand, and so I believe that MySqlCommand simply doesn't support delimiters. Here is the updated code, which works fine:
MySqlScript script = new MySqlScript(connection, #"CREATE TRIGGER update_last_modified
BEFORE INSERT ON users
FOR EACH ROW
BEGIN
DECLARE miscdataWithDate JSON;
IF JSON_CONTAINS_PATH(NEW.miscdata, 'all', '$.v1.lastModified') THEN
SET NEW.miscdata = JSON_REPLACE(NEW.miscdata, '$.v1.lastModified', UTC_TIMESTAMP());
ELSE
SET miscdataWithDate = JSON_SET('{""v1"": {}}', '$.v1.lastModified', UTC_TIMESTAMP());
SET NEW.miscdata = JSON_MERGE(NEW.miscdata, miscdataWithDate);
END IF;
END; //");
script.Delimiter = "//";
await script.ExecuteAsync().ConfigureAwait(false);

MySQL batch-file call flush tables for export

I use batch-file for copy database from server1 to server2.
Step 1: call stored procedure for FLUSH TABLES table1,table2, ..., table1000 FOR EXPORT;
Step 2: copy files .ibd and .cfg to temp directory and archive this
Step 3: unlock tables;
The problem is the first step - files .cfg are created and then removed, but unlock the tables is not called. Why? Files .cfg are created and immediately disappear, I do not have time to copy
.bat file command:
mysql -u %db_user% -p%db_password% %db_name% --default-character-set=utf8 < stored_proc_flush_tables.sql
file stored_proc_flush_tables.sql:
DROP PROCEDURE IF EXISTS stored_proc_flush_tables;
DELIMITER //
CREATE PROCEDURE stored_proc_flush_tables
(
)
BEGIN
DECLARE t_name BLOB;
DECLARE tmp_query BLOB;
DECLARE done_tables INT DEFAULT 0;
DECLARE cursor_tables CURSOR FOR
SELECT table_name FROM information_schema.tables WHERE table_schema=DB_NAME;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done_tables = 1;
SET #table_name = '';
SET #tmp_query = '';
OPEN cursor_tables;
tables_loop: LOOP
FETCH cursor_tables INTO t_name;
IF done_tables = 1 THEN
LEAVE tables_loop;
END IF;
SET #tmp_query = CONCAT_WS('', #tmp_query, ',', t_name);
END LOOP;
CLOSE cursor_tables;
SET #tmp_query = TRIM(LEADING ',' FROM #tmp_query);
SET #tmp_query = CONCAT_WS('', 'FLUSH TABLES', ' ', #tmp_query, ' ', 'FOR EXPORT');
PREPARE stmt FROM #tmp_query;
EXECUTE stmt;
END //
DELIMITER ;
call stored_proc_flush_tables();
Files .cfg are created and immediately disappear, I do not have time to copy them
Problem is that you end mysql session that makes FLUSH TABLES ... FOR EXPORT
before you try to copy files.
When mysql session/connection ends all locks unlocked and *.cfg is consired as temporal file is deleted.
So you should have program that makes FLUSH ... FOR EXPORT and keeps session
open and then copies files and after that releases table lock (or ends session).

PHP.ini Mysql issues

I've spent a lot of time trying to fix this issues. I keep getting a Fatal error: Call to undefined function mysql_connect() error so I did some net trawling and others are having the same problem but manage to fix it by including 'extension=' and un-commenting 'extension=php_mysql.dll' but as you can see doing both of those things still don't work. What have a missed?
MY PHP ini (I am on Windows 7) (Trimmed!)
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
include_path = ".;c:\php\includes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues. The alternate is to use the
; cgi.force_redirect configuration below
; http://php.net/doc-root
doc_root =
; The directory under which PHP opens the script using /~username used only
; if nonempty.
; http://php.net/user-dir
user_dir =
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"
; Whether or not to enable the dl() function. The dl() function does NOT work
; properly in multithreaded servers, such as IIS or Zeus, and is automatically
; disabled on them.
; http://php.net/enable-dl
enable_dl = Off
; cgi.force_redirect is necessary to provide security running PHP as a CGI under
; most web servers. Left undefined, PHP turns this on by default. You can
; turn it off here AT YOUR OWN RISK
; **You CAN safely turn this off for IIS, in fact, you MUST.**
; http://php.net/cgi.force-redirect
;cgi.force_redirect = 1
; if cgi.nph is enabled it will force cgi to always sent Status: 200 with
; every request. PHP's default behavior is to disable this feature.
;cgi.nph = 1
; if cgi.force_redirect is turned on, and you are not running under Apache or Netscape
; (iPlanet) web servers, you MAY need to set an environment variable name that PHP
; will look for to know it is OK to continue execution. Setting this variable MAY
; cause security issues, KNOW WHAT YOU ARE DOING FIRST.
; http://php.net/cgi.redirect-status-env
;cgi.redirect_status_env =
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
;cgi.fix_pathinfo=1
; FastCGI under IIS (on WINNT based OS) supports the ability to impersonate
; security tokens of the calling client. This allows IIS to define the
; security context that the request runs under. mod_fastcgi under Apache
; does not currently support this feature (03/17/2002)
; Set to 1 if running under IIS. Default is zero.
; http://php.net/fastcgi.impersonate
;fastcgi.impersonate = 1
; Disable logging through FastCGI connection. PHP's default behavior is to enable
; this feature.
;fastcgi.logging = 0
; cgi.rfc2616_headers configuration option tells PHP what type of headers to
; use when sending HTTP response code. If it's set 0 PHP sends Status: header that
; is supported by Apache. When this option is set to 1 PHP will send
; RFC2616 compliant header.
; Default is zero.
; http://php.net/cgi.rfc2616-headers
;cgi.rfc2616_headers = 0
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 2M
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20
;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-fopen
allow_url_fopen = On
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-include
allow_url_include = Off
; Define the anonymous ftp password (your email address). PHP's default setting
; for this is empty.
; http://php.net/from
;from="john#doe.com"
; Define the User-Agent string. PHP's default setting for this is empty.
; http://php.net/user-agent
;user_agent="PHP"
; Default timeout for socket based streams (seconds)
; http://php.net/default-socket-timeout
default_socket_timeout = 60
; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from
; unix or win32 systems, setting this flag will cause PHP to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; http://php.net/auto-detect-line-endings
;auto_detect_line_endings = Off
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
extension=c:\PHP\ext\msql.dll
;
; ... or under UNIX:
;
; extension=c:\PHP\ext\msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
;
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
;
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_fileinfo.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_exif.dll ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
[CLI Server]
; Whether the CLI web server uses ANSI color coding in its terminal output.
cli_server.color = On
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
; http://php.net/date.default-latitude
;date.default_latitude = 31.7667
; http://php.net/date.default-longitude
;date.default_longitude = 35.2333
; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333
; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333
[filter]
; http://php.net/filter.default
;filter.default = unsafe_raw
; http://php.net/filter.default-flags
;filter.default_flags =
[iconv]
;iconv.input_encoding = ISO-8859-1
;iconv.internal_encoding = ISO-8859-1
;iconv.output_encoding = ISO-8859-1
[intl]
;intl.default_locale =
; This directive allows you to produce PHP errors when some error
; happens within intl functions. The value is the level of the error produced.
; Default is 0, which does not produce any errors.
;intl.error_level = E_WARNING
[sqlite]
; http://php.net/sqlite.assoc-case
;sqlite.assoc_case = 0
[sqlite3]
;sqlite3.extension_dir =
[Pcre]
;PCRE library backtracking limit.
; http://php.net/pcre.backtrack-limit
;pcre.backtrack_limit=100000
;PCRE library recursion limit.
;Please note that if you set this value to a high number you may consume all
;the available process stack and eventually crash PHP (due to reaching the
;stack size limit imposed by the Operating System).
; http://php.net/pcre.recursion-limit
;pcre.recursion_limit=100000
[Pdo]
; Whether to pool ODBC connections. Can be one of "strict", "relaxed" or "off"
; http://php.net/pdo-odbc.connection-pooling
;pdo_odbc.connection_pooling=strict
;pdo_odbc.db2_instance_name
[Pdo_mysql]
; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/pdo_mysql.cache_size
pdo_mysql.cache_size = 2000
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket=
[Phar]
; http://php.net/phar.readonly
;phar.readonly = On
; http://php.net/phar.require-hash
;phar.require_hash = On
;phar.cache_list =
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me#example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
;mail.log = syslog
[SQL]
; http://php.net/sql.safe-mode
sql.safe_mode = Off
[ODBC]
; http://php.net/odbc.default-db
;odbc.default_db = Not yet implemented
; http://php.net/odbc.default-user
;odbc.default_user = Not yet implemented
; http://php.net/odbc.default-pw
;odbc.default_pw = Not yet implemented
; Controls the ODBC cursor model.
; Default: SQL_CURSOR_STATIC (default).
;odbc.default_cursortype
; Allow or prevent persistent links.
; http://php.net/odbc.allow-persistent
odbc.allow_persistent = On
; Check that a connection is still valid before reuse.
; http://php.net/odbc.check-persistent
odbc.check_persistent = On
; Maximum number of persistent links. -1 means no limit.
; http://php.net/odbc.max-persistent
odbc.max_persistent = -1
; Maximum number of links (persistent + non-persistent). -1 means no limit.
; http://php.net/odbc.max-links
odbc.max_links = -1
; Handling of LONG fields. Returns number of bytes to variables. 0 means
; passthru.
; http://php.net/odbc.defaultlrl
odbc.defaultlrl = 4096
; Handling of binary data. 0 means passthru, 1 return as is, 2 convert to char.
; See the documentation on odbc_binmode and odbc_longreadlen for an explanation
; of odbc.defaultlrl and odbc.defaultbinmode
; http://php.net/odbc.defaultbinmode
odbc.defaultbinmode = 1
;birdstep.max_links = -1
[Interbase]
; Allow or prevent persistent links.
ibase.allow_persistent = 1
; Maximum number of persistent links. -1 means no limit.
ibase.max_persistent = -1
; Maximum number of links (persistent + non-persistent). -1 means no limit.
ibase.max_links = -1
; Default database name for ibase_connect().
;ibase.default_db =
; Default username for ibase_connect().
;ibase.default_user =
; Default password for ibase_connect().
;ibase.default_password =
; Default charset for ibase_connect().
;ibase.default_charset =
; Default timestamp format.
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
; Default date format.
ibase.dateformat = "%Y-%m-%d"
; Default time format.
ibase.timeformat = "%H:%M:%S"
[MySQL]
; Allow accessing, from PHP's perspective, local files with LOAD DATA statements
; http://php.net/mysql.allow_local_infile
mysql.allow_local_infile = On
; Allow or prevent persistent links.
; http://php.net/mysql.allow-persistent
mysql.allow_persistent = On
; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/mysql.cache_size
mysql.cache_size = 2000
; Maximum number of persistent links. -1 means no limit.
; http://php.net/mysql.max-persistent
mysql.max_persistent = -1
; Maximum number of links (persistent + non-persistent). -1 means no limit.
; http://php.net/mysql.max-links
mysql.max_links = -1
; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
; http://php.net/mysql.default-port
mysql.default_port =
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysql.default-socket
mysql.default_socket =
; Default host for mysql_connect() (doesn't apply in safe mode).
; http://php.net/mysql.default-host
mysql.default_host =
; Default user for mysql_connect() (doesn't apply in safe mode).
; http://php.net/mysql.default-user
mysql.default_user =
; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
; http://php.net/mysql.default-password
mysql.default_password =
; Maximum time (in seconds) for connect timeout. -1 means no limit
; http://php.net/mysql.connect-timeout
mysql.connect_timeout = 60
; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
; http://php.net/mysql.trace-mode
mysql.trace_mode = Off
[MySQLi]
; Maximum number of persistent links. -1 means no limit.
; http://php.net/mysqli.max-persistent
mysqli.max_persistent = -1
; Allow accessing, from PHP's perspective, local files with LOAD DATA statements
; http://php.net/mysqli.allow_local_infile
;mysqli.allow_local_infile = On
; Allow or prevent persistent links.
; http://php.net/mysqli.allow-persistent
mysqli.allow_persistent = On
; Maximum number of links. -1 means no limit.
; http://php.net/mysqli.max-links
mysqli.max_links = -1
; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/mysqli.cache_size
mysqli.cache_size = 2000
; Default port number for mysqli_connect(). If unset, mysqli_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
; http://php.net/mysqli.default-port
mysqli.default_port = 3306
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysqli.default-socket
mysqli.default_socket =
; Default host for mysql_connect() (doesn't apply in safe mode).
; http://php.net/mysqli.default-host
mysqli.default_host =
; Default user for mysql_connect() (doesn't apply in safe mode).
; http://php.net/mysqli.default-user
mysqli.default_user =
; Default password for mysqli_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
; http://php.net/mysqli.default-pw
mysqli.default_pw =
; Allow or prevent reconnect
mysqli.reconnect = Off
[mysqlnd]
; Enable / Disable collection of general statistics by mysqlnd which can be
; used to tune and monitor MySQL operations.
; http://php.net/mysqlnd.collect_statistics
mysqlnd.collect_statistics = On
; Enable / Disable collection of memory usage statistics by mysqlnd which can be
; used to tune and monitor MySQL operations.
; http://php.net/mysqlnd.collect_memory_statistics
mysqlnd.collect_memory_statistics = On
; Size of a pre-allocated buffer used when sending commands to MySQL in bytes.
; http://php.net/mysqlnd.net_cmd_buffer_size
;mysqlnd.net_cmd_buffer_size = 2048
; Size of a pre-allocated buffer used for reading data sent by the server in
; bytes.
; http://php.net/mysqlnd.net_read_buffer_size
;mysqlnd.net_read_buffer_size = 32768
[OCI8]
; Connection: Enables privileged connections using external
; credentials (OCI_SYSOPER, OCI_SYSDBA)
; http://php.net/oci8.privileged-connect
;oci8.privileged_connect = Off
; Connection: The maximum number of persistent OCI8 connections per
; process. Using -1 means no limit.
; http://php.net/oci8.max-persistent
;oci8.max_persistent = -1
; Connection: The maximum number of seconds a process is allowed to
; maintain an idle persistent connection. Using -1 means idle
; persistent connections will be maintained forever.
; http://php.net/oci8.persistent-timeout
;oci8.persistent_timeout = -1
; Connection: The number of seconds that must pass before issuing a
; ping during oci_pconnect() to check the connection validity. When
; set to 0, each oci_pconnect() will cause a ping. Using -1 disables
; pings completely.
; http://php.net/oci8.ping-interval
;oci8.ping_interval = 60
; Connection: Set this to a user chosen connection class to be used
; for all pooled server requests with Oracle 11g Database Resident
; Connection Pooling (DRCP). To use DRCP, this value should be set to
; the same string for all web servers running the same application,
; the database pool must be configured, and the connection string must
; specify to use a pooled server.
;oci8.connection_class =
; High Availability: Using On lets PHP receive Fast Application
; Notification (FAN) events generated when a database node fails. The
; database must also be configured to post FAN events.
;oci8.events = Off
; Tuning: This option enables statement caching, and specifies how
; many statements to cache. Using 0 disables statement caching.
; http://php.net/oci8.statement-cache-size
;oci8.statement_cache_size = 20
; Tuning: Enables statement prefetching and sets the default number of
; rows that will be fetched automatically after statement execution.
; http://php.net/oci8.default-prefetch
;oci8.default_prefetch = 100
; Compatibility. Using On means oci_close() will not close
; oci_connect() and oci_new_connect() connections.
; http://php.net/oci8.old-oci-close-semantics
;oci8.old_oci_close_semantics = Off
[PostgreSQL]
; Allow or prevent persistent links.
; http://php.net/pgsql.allow-persistent
pgsql.allow_persistent = On
; Detect broken persistent links always with pg_pconnect().
; Auto reset feature requires a little overheads.
; http://php.net/pgsql.auto-reset-persistent
pgsql.auto_reset_persistent = Off
; Maximum number of persistent links. -1 means no limit.
; http://php.net/pgsql.max-persistent
pgsql.max_persistent = -1
; Maximum number of links (persistent+non persistent). -1 means no limit.
; http://php.net/pgsql.max-links
pgsql.max_links = -1
; Ignore PostgreSQL backends Notice message or not.
; Notice message logging require a little overheads.
; http://php.net/pgsql.ignore-notice
pgsql.ignore_notice = 0
; Log PostgreSQL backends Notice message or not.
; Unless pgsql.ignore_notice=0, module cannot log notice message.
; http://php.net/pgsql.log-notice
pgsql.log_notice = 0
[Sybase-CT]
; Allow or prevent persistent links.
; http://php.net/sybct.allow-persistent
sybct.allow_persistent = On
; Maximum number of persistent links. -1 means no limit.
; http://php.net/sybct.max-persistent
sybct.max_persistent = -1
; Maximum number of links (persistent + non-persistent). -1 means no limit.
; http://php.net/sybct.max-links
sybct.max_links = -1
; Minimum server message severity to display.
; http://php.net/sybct.min-server-severity
sybct.min_server_severity = 10
; Minimum client message severity to display.
; http://php.net/sybct.min-client-severity
sybct.min_client_severity = 10
; Set per-context timeout
; http://php.net/sybct.timeout
;sybct.timeout=
;sybct.packet_size
; The maximum time in seconds to wait for a connection attempt to succeed before returning failure.
; Default: one minute
;sybct.login_timeout=
; The name of the host you claim to be connecting from, for display by sp_who.
; Default: none
;sybct.hostname=
; Allows you to define how often deadlocks are to be retried. -1 means "forever".
; Default: 0
;sybct.deadlock_retry_count=
[bcmath]
; Number of decimal digits for all bcmath functions.
; http://php.net/bcmath.scale
bcmath.scale = 0
[browscap]
; http://php.net/browscap
;browscap = extra/browscap.ini
[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
session.save_handler = files
; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
;
; The path can be defined as:
;
; session.save_path = "N;/path"
;
; where N is an integer. Instead of storing all the session files in
; /path, what this will do is use subdirectories N-levels deep, and
; store the session data in those directories. This is useful if you
; or your OS have problems with lots of files in one directory, and is
; a more efficient layout for servers that handle lots of sessions.
;
; NOTE 1: PHP will not create this directory structure automatically.
; You can use the script in the ext/session dir for that purpose.
; NOTE 2: See the section on garbage collection below if you choose to
; use subdirectories for session storage
;
; The file storage module creates files using mode 600 by default.
; You can change that by using
;
; session.save_path = "N;MODE;/path"
;
; where MODE is the octal representation of the mode. Note that this
; does not overwrite the process's umask.
; http://php.net/session.save-path
;session.save_path = "/tmp"
; Whether to use cookies.
; http://php.net/session.use-cookies
session.use_cookies = 1
; http://php.net/session.cookie-secure
;session.cookie_secure =
; This option forces PHP to fetch and use a cookie for storing and maintaining
; the session id. We encourage this operation as it's very helpful in combating
; session hijacking when not specifying and managing your own session id. It is
; not the end all be all of session hijacking defense, but it's a good start.
; http://php.net/session.use-only-cookies
session.use_only_cookies = 1
; Name of the session (used as cookie name).
; http://php.net/session.name
session.name = PHPSESSID
; Initialize session on request startup.
; http://php.net/session.auto-start
session.auto_start = 0
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
; http://php.net/session.cookie-lifetime
session.cookie_lifetime = 0
Cheers
Be sure to appropriately set the extension_dir directive.
Make sure that the .dll is in your extension folder. Then, try defining extension_dir.
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"

SQL - shrink database log file

I am trying to shrink my database log file. I have tried to run:
USE databasename
BACKUP log databasename
WITH truncate_only
DBCC shrinkfile (databasename_log, 1)
I get the error message:
Msg 155, Level 15, State 1, Line 3
'truncate_only' is not a recognized
BACKUP option.
Am I missing something?
SQL Server 2008 no longer allows the NO_LOG / TRUNCATE_ONLY options.
To truncate your transaction log, you either have to back it up (for real) or switch the database's Recovery Model to Simple. The latter is probably what you really want here. You don't need Full recovery unless you are making regular transaction log backups to be able to restore to some point mid-day.
I think the best way is to use a script like this:
USE AdventureWorks
GO
-- Use some dynamic SQL just only not to re-write several times the name
-- of your db, or to insert this snippet into a loop for all your databases...
DECLARE #dbname varchar(50) = 'AdventureWorks';
DECLARE #logFileName varchar(50) = #dbname + '_log';
DECLARE #SQL nvarchar(max);
SET #SQL = REPLACE('ALTER DATABASE {dbname} SET RECOVERY FULL;', '{dbname}', #dbname);
EXECUTE(#SQL);
DECLARE #path nvarchar(255) = N'F:\BCK_DB\logBCK' + CONVERT(CHAR(8), GETDATE(), 112) + '_'
+ REPLACE(CONVERT(CHAR(8), GETDATE(), 108),':','') + '.trn';
BACKUP LOG #dbname TO DISK = #path WITH INIT, COMPRESSION;
DBCC SHRINKFILE(#logFileName);
-- determine here the new file size and growth rate:
SET #SQL = REPLACE('ALTER DATABASE {dbname} MODIFY FILE (NAME = ' + #logFileName + ', SIZE = 32000MB, FILEGROWTH = 10%);',
'{dbname}', #dbname);
EXECUTE(#SQL);
GO
http://www.snip2code.com/Snippet/12913/How-to-correctly-Shrink-Log-File-for-SQL