<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL | DXSdata</title>
	<atom:link href="https://www.dxsdata.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dxsdata.com</link>
	<description>Software &#124; Network &#124; Administration</description>
	<lastBuildDate>Thu, 06 Dec 2018 18:48:04 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://www.dxsdata.com/wp-content/uploads/2023/08/cropped-logo-32x32.jpg</url>
	<title>MySQL | DXSdata</title>
	<link>https://www.dxsdata.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>[:de].NET: LINQ SQL-Queries mit AutoMapper optimieren[:en].NET: Optimizing LINQ SQL queries with AutoMapper[:]</title>
		<link>https://www.dxsdata.com/2018/12/net-optimizing-linq-sql-queries-with-automapper/</link>
					<comments>https://www.dxsdata.com/2018/12/net-optimizing-linq-sql-queries-with-automapper/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 06 Dec 2018 18:48:04 +0000</pubDate>
				<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">https://www.dxsdata.com/?p=2052</guid>

					<description><![CDATA[[:en]AutoMapper is not only a useful tool for mapping e.g. DB model classes to flatter ViewModels, it can also simplify and optimize SQL queries / expressions generated by LINQ. You can get it via NuGet for any .NET framework type. Example Let&#8217;s suppose we have a simple DB table User. Each user belongs to a [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]AutoMapper is not only a useful tool for mapping e.g. DB model classes to flatter ViewModels, it can also simplify and optimize SQL queries / expressions generated by LINQ.</p>
<p>You can get it via NuGet for any .NET framework type.</p>
<h2>Example</h2>
<p>Let&#8217;s suppose we have a simple DB table <strong>User</strong>. Each user belongs to a <strong>UserGroup</strong> and owns several items, stored in <strong>UserItem</strong>. The tables are &#8220;connected&#8221; via common IDs and SQL foreign keys. The DB classes were generated via common tools like &#8220;dotnet ef scaffold&#8221;.</p>
<p>We want to get an overview of the users, including a property of the parent (UserGroup.Name) and a sum of the user&#8217;s items. The table is huge, so the whole preparation and calculation should be done by the server to reduce network traffic.</p>
<p>The data will be stored in a flat ViewModel class <strong>UserView</strong>, which contains the same structure as User, but with 2 additional fields, <em>UserGroupName</em> and <em>UserItemSum</em>.</p>
<p>First we prepare AutoMapper:</p>
<pre title="Program.cs, Startup.cs or similar" class="lang:c# decode:true">//using AutoMapper;
Mapper.Initialize(cfg =&gt;
{
    cfg.CreateMap&lt;User, UserView&gt;()
      .ForMember(uview =&gt; uview.UserItemSum, opt =&gt; opt.MapFrom(user =&gt; user.UserItem.Sum(item =&gt; item.Number)))
});
</pre>
<p>Create the context instance for DB access:</p>
<pre title="anyClass.cs" class="lang:c# decode:true">var db = new mydbContext();

var dto = db.User.ProjectTo&lt;UserView&gt;().ToList();

//example for proceeding
myBindingSourceForDataGrid.DataSource = dto;</pre>
<p>&#8230;and that was about it. We do not need any more Include() of subtables, Where(), Select() or anything else, and the whole query is run on the server side (the SQL server).</p>
<p>AutoMapper is smart enough to recognize that the UserView.UserGroupName column should belong to the user&#8217;s UserGroup.Name property.</p>
<p>In CreateMap(), we just need to tell how it handles the UserItemSum column.</p>
<p>Taking a look at the SQL query log, we see that the query in fact contains only the needed data:</p>
<pre class="lang:mysql decode:true ">SELECT `User`.`Fullname`, `User.UserGroup`.`Name` AS `UserGroupName`, `User`.`id`, (
    SELECT SUM(`item`.`Number`)
    FROM `mydb`.`UserItem` AS `item`
    WHERE `User`.`id` = `item`.`userId`
) AS `UserItemSum`
FROM `mydb`.`User` AS `User`
INNER JOIN `mydb`.`UserGroup` AS `User.UserGroup` ON `User`.`UserGroupid` = `User.UserGroup`.`id`</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>References</h3>
<p>http://docs.automapper.org/en/stable/Queryable-Extensions.html</p>
<p>&nbsp;</p>
<p>&nbsp;[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2018/12/net-optimizing-linq-sql-queries-with-automapper/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[:de]Ubuntu Upgrade von 14 Trusty auf 16 Xenial, MySQL-Probleme beheben[:en]Ubuntu upgrade from 14 Trusty to 16 Xenial, solve MySQL issues[:]</title>
		<link>https://www.dxsdata.com/2017/04/ubuntu-upgrade-from-14-trusty-to-16-xenial-solve-mysql-issues/</link>
					<comments>https://www.dxsdata.com/2017/04/ubuntu-upgrade-from-14-trusty-to-16-xenial-solve-mysql-issues/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 29 Apr 2017 12:54:42 +0000</pubDate>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1755</guid>

					<description><![CDATA[[:en]&#160; Upgrading Ubuntu from v14 to 16 LTS can lead to MySQL server issues (MySQL is upgraded from v5.6 to 5.7 during the upgrade process). E.g. if you use deprecated variables in /etc/mysql/my.cnf, MySQL server will fail to start after the upgrade is finished. My recommendations for the upgrade: If the server is a virtual [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]&nbsp;</p>
<p>Upgrading Ubuntu from v14 to 16 LTS can lead to MySQL server issues (MySQL is upgraded from v5.6 to 5.7 during the upgrade process).</p>
<p>E.g. if you use deprecated variables in /etc/mysql/my.cnf, MySQL server will fail to start after the upgrade is finished.</p>
<p>My recommendations for the upgrade:</p>
<ol>
<li>If the server is a virtual appliance, create a snapshot when the system is shut down. Otherwise create a full backup.</li>
<li>Within Ubuntu v14, do an &#8220;apt-get update &amp;&amp; apt-get upgrade&#8221; and check if everything is running fine.</li>
<li>Create a snapshot again.</li>
<li>Edit /etc/mysql/my.cnf. In my case I had to delete variables
<ol>
<li>table_cache</li>
<li>log-slow-queries</li>
<li>(long query time)</li>
</ol>
</li>
<li>Run &#8220;do-release-upgrade&#8221; to v16 Xenial.</li>
<li>If you are using phpMyAdmin, the dbcommon upgrade procedure might fail during the upgrade process (&#8220;cannot access mysqld.sock&#8221; or similar). Simply ignore it for now.</li>
<li>When the upgrade is finished, check if MySQL is running (&#8220;ps ax&#8221;) and if not, try to start it manually (e.g. &#8220;service mysql restart&#8221;).
<ol>
<li>If MySQL server is unable to start, look at /var/log/mysql/error.log, maybe you have to modify my.cnf again, e.g. remove further certain variables. In this case, I recommend to note the vars and start from the latest snapshot again.</li>
</ol>
</li>
<li>If you have huge MySQL databases, watch /var/log/mysql/error.log and/or mysql.log. It might take several minutes as some DB types might be converted to newer formats in all tables.</li>
<li>Check if phpMyAdmin works. If Dbcommon failed during the upgrade, run &#8220;dpkg-reconfigure phpmyadmin&#8221;.</li>
</ol>
<p>&nbsp;</p>
<p>Additions:</p>
<p>It turned out that more modifications are necessary:</p>
<p>MySQL 5.7 seems to ignore max_connections value. If it is e.g. set to 600 in my.cnf, it still uses value 214.</p>
<p>To solve this issue, we have to do a few more adaptions.</p>
<pre title="/lib/systemd/system/mysql.service" class="lang:sh decode:true">LimitNOFILE=infinity
LimitMEMLOCK=infinity</pre>
<p>&nbsp;</p>
<pre title="/etc/security/limits.conf" class="lang:sh decode:true ">* soft nofile 1024000
* hard nofile 1024000
* soft nproc 10240
* hard nproc 10240</pre>
<p>&nbsp;</p>
<pre title="/etc/mysql/my.cnf" class="lang:sh decode:true ">open_files_limit = 1024000
table_open_cache = 500</pre>
<p>Optionally, also decrease the timeout values:</p>
<pre title="/etc/mysql/my.cnf" class="lang:sh decode:true ">wait_timeout = 5000
interactive_timeout = 5000</pre>
<p>Run afterwards:</p>
<pre class="lang:sh decode:true ">systemctl daemon-reload
service mysql restart</pre>
<p>Check the currently used max_connections value e.g. with phpMyAdmin or MySQL console.</p>
<p>Update 2017-05-04:</p>
<p>If you encounter further MySQL errors like &#8220;ERROR 1366 Incorrect integer value: &#8221; for column &#8216;xx&#8217; at row xx, you might want to change sql_mode&#8217;s value to the default one from v5.6 (if modifying the SQL query is not an option):</p>
<pre title="/etc/mysql/my.cnf" class="lang:sh decode:true">sql_mode=NO_ENGINE_SUBSTITUTION</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://stackoverflow.com/questions/35111698/unable-to-increase-mysql-open-files-limit">Reference</a></p>
<p><a href="https://unix.stackexchange.com/questions/152186/mysql-max-open-files-more-than-1024#answer-157910">Reference</a>[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2017/04/ubuntu-upgrade-from-14-trusty-to-16-xenial-solve-mysql-issues/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[:de]ASP.Net MVC, Entity Framework: Benutzerfreundliche Model-Spaltenbezeichnungen (Metadaten)[:en]ASP.Net MVC, Entity Framework: Show user friendly model column names (Metadata)[:]</title>
		<link>https://www.dxsdata.com/2016/07/asp-net-mvc-entity-framework-show-user-friendly-model-column-names-metadata/</link>
					<comments>https://www.dxsdata.com/2016/07/asp-net-mvc-entity-framework-show-user-friendly-model-column-names-metadata/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 12 Jul 2016 07:04:28 +0000</pubDate>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1172</guid>

					<description><![CDATA[[:en]Databases like MySQL do not allow any special characters in table column names, so most developers use camelcase or underscores. To make it readable for the end user in your software, you often have to manually type a friendly description. As there is no way to set a &#8220;friendly name&#8221; value in the DB table [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]Databases like MySQL do not allow any special characters in table column names, so most developers use camelcase or underscores. To make it readable for the end user in your software, you often have to manually type a friendly description.</p>
<p>As there is no way to set a &#8220;friendly name&#8221; value in the DB table structure directly, you might think of putting some additional data into the .Net database entity  model. This is not always a good idea, because data could get lost when you update your model structure from DB.</p>
<p>So the most useful way I found so far in ASP.Net is to use a combination of System.ComponentModel.DataAnnotations and Model Metadata.</p>
<p><strong>Example</strong></p>
<p>You have a table mytable in your model mymodel, which contains a column mycolumn. The friendly name for mycolumn should be &#8220;My Column&#8221;.</p>
<p>In your Models folder (Visual Studio Solution Explorer), create 2 class files called MetaData.cs and PartialClasses.cs.</p>
<p>&nbsp;</p>
<pre title="MetaData.cs" class="lang:c# decode:true ">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace myproject.Models
{
    public class MetaData
    {
        public class mytableMetaData
        {
            [Display(Name = "My Column")]
            public object mycolumn;
            

        }
    }
}

</pre>
<pre title="PartialClasses.cs" class="lang:c# decode:true ">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace myproject.Models
{    
    [MetadataType(typeof(MetaData.mytableMetaData))]
    public partial class mytable
    {
    }
}</pre>
<p>In your .cshtml file, use:</p>
<pre class="lang:c# decode:true">@Html.DisplayNameFor(m =&gt; m.mycolumn)</pre>
<p>You should now see the friendly column name &#8220;My Column&#8221; in your browser.</p>
<p>E.g. &#8220;@Html.ValidationSummary()&#8221; now also uses the display name from Metadata.</p>
<p>If you refresh your model structure later, these two classes are not affected.</p>
<p><a href="http://www.asp.net/mvc/overview/getting-started/database-first-development/enhancing-data-validation">Reference</a>[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2016/07/asp-net-mvc-entity-framework-show-user-friendly-model-column-names-metadata/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[:de]MySQL: Alle Abfragen / Prozesse eines bestimmten Benutzers beenden[:en]MySQL: Kill all queries / processes of certain user[:]</title>
		<link>https://www.dxsdata.com/2016/06/mysql-kill-all-queries-processes-of-certain-user/</link>
					<comments>https://www.dxsdata.com/2016/06/mysql-kill-all-queries-processes-of-certain-user/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 22 Jun 2016 10:16:46 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1151</guid>

					<description><![CDATA[[:en]Open your MySQL client or phpMyAdmin etc. Execute query: select concat('KILL ',id,';') from information_schema.processlist where user='yourUser' Copy the result lines and execute them, it should look like: kill 12345; kill 12346; kill 12347; ... Reference[:]]]></description>
										<content:encoded><![CDATA[<p>[:en]Open your MySQL client or phpMyAdmin etc.</p>
<p>Execute query:</p>
<pre class="lang:mysql decode:true ">select concat('KILL ',id,';') from information_schema.processlist where user='yourUser'</pre>
<p>Copy the result lines and execute them, it should look like:</p>
<pre class="lang:sh decode:true ">kill 12345;
kill 12346;
kill 12347;
...</pre>
<p><a href="https://www.percona.com/blog/2009/05/21/mass-killing-of-mysql-connections/">Reference</a>[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2016/06/mysql-kill-all-queries-processes-of-certain-user/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL: Query Logging aktivieren ohne NeustartMySQL: Enable query logging during runtime without restart</title>
		<link>https://www.dxsdata.com/2016/01/mysql-enable-query-logging-during-runtime-without-restart/</link>
					<comments>https://www.dxsdata.com/2016/01/mysql-enable-query-logging-during-runtime-without-restart/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 19 Jan 2016 13:32:29 +0000</pubDate>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1051</guid>

					<description><![CDATA[Log in to MySQL via console: mysql -u root -p Run: SET global log_output = 'table'; SET global general_log = 1; View table mysql.general_log e.g. with phpMyAdmin or command: select * from mysql.general_log Do not forget to disable logging again: SET global general_log = 0; Source]]></description>
										<content:encoded><![CDATA[<p><!--:en-->Log in to MySQL via console:</p>
<pre class="lang:sh decode:true ">mysql -u root -p
</pre>
<p>Run:</p>
<pre class="lang:sh decode:true">SET global log_output = 'table';
SET global general_log = 1;</pre>
<p>View table mysql.general_log e.g. with phpMyAdmin or command:</p>
<pre class="lang:sh decode:true ">select * from mysql.general_log</pre>
<p>Do not forget to disable logging again:</p>
<pre class="lang:sh decode:true ">SET global general_log = 0;</pre>
<p><a href="http://stackoverflow.com/questions/303994/log-all-queries-in-mysql/14403905#14403905"> Source</a><!--:--></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2016/01/mysql-enable-query-logging-during-runtime-without-restart/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Tipps zur MySQL Leistungsoptimierung mit IndexenBasic hints for MySQL performance optimization using Indexes</title>
		<link>https://www.dxsdata.com/2015/11/basic-hints-for-mysql-performance-optimization-using-indexes/</link>
					<comments>https://www.dxsdata.com/2015/11/basic-hints-for-mysql-performance-optimization-using-indexes/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 04 Nov 2015 10:03:55 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1005</guid>

					<description><![CDATA[Problem An SQL query containing multiple table joins, functions etc. is too slow, but necessary. Solution approaches Indexes created on single or multiple MySQL table columns can increase performance in a significant way if they are used correctly. First, have a look at the MySQL Explain command. Simply add &#8220;explain &#8221; at the beginning of your [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><!--:en--><strong>Problem</strong></p>
<p>An SQL query containing multiple table joins, functions etc. is too slow, but necessary.</p>
<p><strong>Solution approaches</strong></p>
<p>Indexes created on single or multiple MySQL table columns can increase performance in a significant way if they are used correctly.</p>
<p>First, have a look at the <a href="http://dev.mysql.com/doc/refman/5.7/en/explain.html">MySQL Explain</a> command. Simply add &#8220;explain &#8221; at the beginning of your query and execute it. E.g. in <a href="http://www.phpmyadmin.net/">phpMyAdmin</a>, you get a table which shows which keys (indexes) are available and which ones are used. If you see many NULL values or high row/reference numbers in this table, your table indexes have to get optimized.</p>
<p>&nbsp;</p>
<p>If you have a query like this,</p>
<pre class="lang:mysql decode:true">select bla from `user` where lastname = 'asdf'</pre>
<p>it is a good idea to create an index for column &#8220;lastname&#8221;.</p>
<p>&nbsp;</p>
<p>Using this query,</p>
<pre class="lang:sh decode:true">select max(logindate) from `user` where lastname = 'asdf'</pre>
<p>the index should contain both columns &#8220;logindate&#8221; and &#8220;lastname&#8221;. Note, if you create an index &#8220;(lastname, logindate)&#8221;, a separate index containing only &#8220;lastname&#8221; is not needed any more.</p>
<p>&nbsp;</p>
<p>Using multiple joins like,</p>
<pre class="lang:sh decode:true">select a.asdf, b.bsdf, c.csdf
from a
left join a.id on b.aid
left join a.id on c.aid</pre>
<p>make sure each of b.aid and c.aid is indexed. Additionally, the joined columns must have the same type and length for the index to be used.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html">Reference</a><!--:--></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2015/11/basic-hints-for-mysql-performance-optimization-using-indexes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL: Find all references to a table before moving it</title>
		<link>https://www.dxsdata.com/2014/09/mysql-find-all-references-to-a-table-before-moving-it/</link>
					<comments>https://www.dxsdata.com/2014/09/mysql-find-all-references-to-a-table-before-moving-it/#respond</comments>
		
		<dc:creator><![CDATA[ds]]></dc:creator>
		<pubDate>Thu, 25 Sep 2014 12:08:28 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://dev.schausberger.cc/?p=190</guid>

					<description><![CDATA[Scenario You have to move a MySQL database table to another database, but you have many other tables, functions, routines, events etc. which access it. Before moving it, it is not enough to find only the tables containing foreign keys, but also find functions etc. which use it. This PHP script does that for you: [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>Scenario</strong></p>
<p>You have to move a MySQL database table to another database, but you have many other tables, functions, routines, events etc. which access it. Before moving it, it is not enough to find only the tables containing foreign keys, but also find functions etc. which use it.</p>
<p>This PHP script does that for you: <a href="https://www.dxsdata.com/wp-content/uploads/2014/09/mysql_table_references.zip">mysql_table_references</a></p>
<p><strong>Usage</strong></p>
<p>Edit the script to enter your DB server login data, then run it in your browser and enter the table name which you want to find references for.</p>
<p><strong>Script code</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css&quot;&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;?php
    $searchtable = @$_GET&#x5B;'searchtable'];
?&gt;

&lt;h1&gt;References, Views and Routines regarding Table&lt;/h1&gt;

&lt;form action=&quot;&lt;?=$_SERVER&#x5B;'PHP_SELF']?&gt;&quot; method=&quot;get&quot;&gt;
Table name: &lt;input type=&quot;text&quot; name=&quot;searchtable&quot; value=&quot;&lt;?=@$searchtable?&gt;&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Search&quot;&gt;
&lt;/form&gt;

&lt;?php
    if (!$searchtable)
        exit;

?&gt;

&lt;?php

$dbhost = 'localhost';
$dbname = 'yourdb';
$dbuser = 'root';
$dbpw = 'yourpw';

try
{
    $db = new PDO(&quot;mysql:host=$dbhost;&quot;, $dbuser, $dbpw);
}
catch(PDOException $ex)
{
    echo &quot;&lt;b&gt;Could not connect to server! Please make sure you have set the correct config values in this file.&lt;/b&gt;&quot;;
    echo &quot;&lt;br&gt;Details:&lt;br&gt;&quot;.$ex-&gt;getMessage();
    exit;
}

//Foreign Keys:
$result = $db-&gt;query(&quot;select
  TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, TABLE_SCHEMA, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
where
  REFERENCED_TABLE_NAME = '$searchtable' or TABLE_NAME = '$searchtable'
  order by TABLE_NAME, REFERENCED_TABLE_NAME;&quot;);
//Alternative?
//  show create table $searchtable;
?&gt;

&lt;div&gt;Note: Results may contain unrelated entries if the table name is not unique, e.g. if it is also used in column names etc.&lt;/div&gt;

&lt;hr&gt;
&lt;h2&gt;Results for &lt;b&gt;&lt;?=$searchtable?&gt;&lt;/b&gt;&lt;/h2&gt;

&lt;h3&gt;Foreign Keys&lt;/h3&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tr&gt;
    &lt;th&gt;DB&lt;/th&gt;
    &lt;th&gt;Table&lt;/th&gt;
    &lt;th&gt;Column&lt;/th&gt;
    &lt;th&gt;Referenced Table&lt;/th&gt;
    &lt;th&gt;Referenced Column&lt;/th&gt;
&lt;/tr&gt;

&lt;?php
while($row = $result-&gt;fetch())
{
     ?&gt;
     &lt;tr&gt;
        &lt;td&gt;&lt;?=$row&#x5B;'TABLE_SCHEMA']?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?=$row&#x5B;'TABLE_NAME']?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?=$row&#x5B;'COLUMN_NAME']?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?=$row&#x5B;'REFERENCED_TABLE_NAME']?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?=$row&#x5B;'REFERENCED_COLUMN_NAME']?&gt;&lt;/td&gt;
     &lt;/tr&gt;
     &lt;?php
}
?&gt;
&lt;/table&gt;
&lt;?php

//Usage in Views:
$result = $db -&gt; query(&quot;select
    TABLE_SCHEMA, TABLE_NAME, VIEW_DEFINITION
    from INFORMATION_SCHEMA.views
    where view_definition like '%from%$searchtable%'
&quot;);

?&gt;
&lt;h3&gt;Views&lt;/h3&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tr&gt;
    &lt;th&gt;DB&lt;/th&gt;
    &lt;th&gt;Table&lt;/th&gt;
    &lt;th&gt;View Definition&lt;/th&gt;
&lt;/tr&gt;

&lt;?php

while($row = $result-&gt;fetch())
{
     ?&gt;
     &lt;tr&gt;
        &lt;td&gt;&lt;?=$row&#x5B;'TABLE_SCHEMA']?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;&lt;?=$row&#x5B;'TABLE_NAME']?&gt;&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;small&gt;&lt;?=nl2br(str_ireplace($searchtable, &quot;&lt;b&gt;$searchtable&lt;/b&gt;&quot;, $row&#x5B;'VIEW_DEFINITION']))?&gt;&lt;/small&gt;&lt;/td&gt;
     &lt;/tr&gt;
     &lt;?php
}

?&gt;
&lt;/table&gt;
&lt;?php

//Usage in Routines:
$result = $db -&gt; query(&quot;select
    ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_DEFINITION
    from INFORMATION_SCHEMA.ROUTINES
    where routine_definition like '%from%$searchtable%'
&quot;);
?&gt;
&lt;h3&gt;Routines&lt;/h3&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tr&gt;
    &lt;th&gt;DB&lt;/th&gt;
    &lt;th&gt;Table&lt;/th&gt;
    &lt;th&gt;Routine Definition&lt;/th&gt;
&lt;/tr&gt;

&lt;?php

while($row = $result-&gt;fetch())
{
     ?&gt;
     &lt;tr&gt;
        &lt;td&gt;&lt;?=$row&#x5B;'ROUTINE_SCHEMA']?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;&lt;?=$row&#x5B;'ROUTINE_NAME']?&gt;&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;small&gt;&lt;?=nl2br(str_ireplace($searchtable, &quot;&lt;b&gt;$searchtable&lt;/b&gt;&quot;, $row&#x5B;'ROUTINE_DEFINITION']))?&gt;&lt;/small&gt;&lt;/td&gt;

     &lt;/tr&gt;
     &lt;?php
}

?&gt;
&lt;/table&gt;
&lt;?php

//Usage in Events:
$result = $db -&gt; query(&quot;select
    EVENT_SCHEMA, EVENT_NAME, EVENT_DEFINITION
    from INFORMATION_SCHEMA.events
    where event_definition like '%from%$searchtable%'
&quot;);

?&gt;
&lt;h3&gt;Events&lt;/h3&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tr&gt;
    &lt;th&gt;DB&lt;/th&gt;
    &lt;th&gt;Table&lt;/th&gt;
    &lt;th&gt;Event Definition&lt;/th&gt;
&lt;/tr&gt;

&lt;?php

while($row = $result-&gt;fetch())
{
     ?&gt;
     &lt;tr&gt;
        &lt;td&gt;&lt;?=$row&#x5B;'EVENT_SCHEMA']?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;&lt;?=$row&#x5B;'EVENT_NAME']?&gt;&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;small&gt;&lt;?=nl2br(str_ireplace($searchtable, &quot;&lt;b&gt;$searchtable&lt;/b&gt;&quot;, $row&#x5B;'EVENT_DEFINITION']))?&gt;&lt;/small&gt;&lt;/td&gt;

     &lt;/tr&gt;
     &lt;?php
}

?&gt;
&lt;/table&gt;

&lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

</pre>
<p>It might also be useful to get all DB users which have access to the table(s). Use phpMyAdmin for this (Activate table, then click &#8220;Permissions&#8221;).</p>
<p>Moving tables to another database might have effect to a lot of software accessing the data, and it could take a long time to get the code updated. During this process, use a workaround like table views. You can reference the new table with the view, so it is accessible via both databases. Using MySQL, you can e.g. use &#8220;update&#8221; or &#8220;insert&#8221; commands directly on the view in many cases, e.g. if there is exactly 1 table in the view query.</p>
<p>Example: create view address as select * from newdb.address</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2014/09/mysql-find-all-references-to-a-table-before-moving-it/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CakePHP, MySQL: Issues with character sets / special chars</title>
		<link>https://www.dxsdata.com/2014/07/cakephp-mysql-issues-with-character-sets-special-chars/</link>
					<comments>https://www.dxsdata.com/2014/07/cakephp-mysql-issues-with-character-sets-special-chars/#comments</comments>
		
		<dc:creator><![CDATA[ds]]></dc:creator>
		<pubDate>Mon, 28 Jul 2014 09:27:20 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://dev.schausberger.cc/?p=181</guid>

					<description><![CDATA[Problem Framework CakePHP sets strings to null which are loaded from database tables and contain special characters like German Umlaute. Solution In app/Config/database.php, add to your config array: &#8216;encoding&#8217; =&#62; &#8216;utf8&#8217; Example: public $default = array( 'datasource' =&#62; 'Database/Mysql', 'persistent' =&#62; false, 'host' =&#62; 'localhost', 'login' =&#62; 'asdf', 'password' =&#62; 'meow', 'database' =&#62; 'bsdf', 'prefix' [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>Problem</strong></p>
<p>Framework CakePHP sets strings to null which are loaded from database tables and contain special characters like German Umlaute.</p>
<p><strong>Solution</strong></p>
<p>In app/Config/database.php, add to your config array: &#8216;<em>encoding&#8217; =&gt; &#8216;utf8&#8217;</em></p>
<p>Example:</p>
<pre class="brush: php; title: ; notranslate">
public $default = array(
		'datasource' =&gt; 'Database/Mysql',
		'persistent' =&gt; false,
		'host' =&gt; 'localhost',
		'login' =&gt; 'asdf',
		'password' =&gt; 'meow',
		'database' =&gt; 'bsdf',
		'prefix' =&gt; '',
		'encoding' =&gt; 'utf8',
	);
</pre>
<p>It seems like this works even if your DB columns have another charset / collation like latin1_swedish_ci.</p>
<p><strong>Notes</strong></p>
<p>If you are using Ajax, make sure you clean the browser&#8217;s cache after modifying the .php file. Otherwise the changes might not be shown immediately.</p>
<p>Basically, it would be also a good idea to use UTF-8 in your DB and all your .php / .ctp files.</p>
<ul>
<li>In MySQL, you have to change the default collation per DB, per table and also the columns themselves. phpMyAdmin is a good choice for doing this. Usually, no problem should appear if you e.g. change from latin to UTF-8, but to be safe create a backup first.</li>
<li>Use collation utf8_unicode_ci, NOT utf8_general_ci! It could end in wrong results.</li>
<li>For your files, if you use a PHP IDE like NuSphere PhpED: Right near the bar under the code window where the line numbers etc. are shown, you see the charset of the file. Click on it to change it to UTF-8. Windows Notepad has similar functions in the Open/Save dialogs.</li>
<li>Make sure you set the correct charset in the header of your PHP files. In CakePHP, UTF-8 is already set in app/Config.core.php.</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2014/07/cakephp-mysql-issues-with-character-sets-special-chars/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL Connector .Net MysqlException: Only MySqlParameter objects may be stored</title>
		<link>https://www.dxsdata.com/2012/06/mysql-connector-net-mysqlexception-only-mysqlparameter-objects-may-be-stored/</link>
					<comments>https://www.dxsdata.com/2012/06/mysql-connector-net-mysqlexception-only-mysqlparameter-objects-may-be-stored/#respond</comments>
		
		<dc:creator><![CDATA[ds]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 10:30:52 +0000</pubDate>
				<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[.Ne]]></category>
		<category><![CDATA[Connector]]></category>
		<category><![CDATA[t Visual Studio 2010]]></category>
		<guid isPermaLink="false">http://dev.schausberger.cc/?p=47</guid>

					<description><![CDATA[This exception is thrown e.g. using the following code in C# .Net 2010: MySqlCommand cmd = new MySqlCommand(&#34;insert into common_history(datetime, username, text) values (@datetime, @username, @text)&#34;, adapter.UpdateCommand.Connection); cmd.Parameters.Add(DateTime.Now); cmd.Parameters.Add(Environment.UserName); cmd.Parameters.Add(text); cmd.BeginExecuteNonQuery(); cmd.Dispose(); Instead, use MySqlCommand cmd = new MySqlCommand(&#34;insert into common_history(datetime, username, text) values (@datetime, @username, @text)&#34;, adapter.UpdateCommand.Connection); cmd.Parameters.AddWithValue(&#34;@datetime&#34;, DateTime.Now); cmd.Parameters.AddWithValue(&#34;@username&#34;,Environment.UserName); cmd.Parameters.AddWithValue(&#34;@text&#34;, text); cmd.BeginExecuteNonQuery(); cmd.Dispose();]]></description>
										<content:encoded><![CDATA[<p>This exception is thrown e.g. using the following code in C# .Net 2010:</p>
<pre class="brush: csharp; title: ; notranslate">

MySqlCommand cmd = new MySqlCommand(&quot;insert into common_history(datetime, username, text) values (@datetime, @username, @text)&quot;, adapter.UpdateCommand.Connection);
cmd.Parameters.Add(DateTime.Now);
cmd.Parameters.Add(Environment.UserName);
cmd.Parameters.Add(text);
cmd.BeginExecuteNonQuery();
cmd.Dispose();

</pre>
<p>Instead, use</p>
<pre class="brush: csharp; title: ; notranslate">

MySqlCommand cmd = new MySqlCommand(&quot;insert into common_history(datetime, username, text) values (@datetime, @username, @text)&quot;, adapter.UpdateCommand.Connection);
cmd.Parameters.AddWithValue(&quot;@datetime&quot;, DateTime.Now);
cmd.Parameters.AddWithValue(&quot;@username&quot;,Environment.UserName);
cmd.Parameters.AddWithValue(&quot;@text&quot;, text);
cmd.BeginExecuteNonQuery();
cmd.Dispose();

</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2012/06/mysql-connector-net-mysqlexception-only-mysqlparameter-objects-may-be-stored/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MySQLDump and VBScript: Dump all databases into separate files with compression</title>
		<link>https://www.dxsdata.com/2012/06/mysqldump-and-vbscript-dump-all-databases-into-separate-files-with-compression/</link>
					<comments>https://www.dxsdata.com/2012/06/mysqldump-and-vbscript-dump-all-databases-into-separate-files-with-compression/#respond</comments>
		
		<dc:creator><![CDATA[ds]]></dc:creator>
		<pubDate>Wed, 13 Jun 2012 11:59:25 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://dev.schausberger.cc/?p=33</guid>

					<description><![CDATA['MySQL Backup Script 'run with &#34;cscript mysql_backup.vbs&#34; 'Configuration server = &#34;www&#34; user = &#34;backup&#34; pw = &#34;BackupPW&#34; mysql = &#34;mysql.exe&#34; mysqldump = &#34;mysqldump.exe&#34; backupdir = &#34;e:mysqlbackupwww&#34; Set objShell = CreateObject(&#34;WScript.Shell&#34;) 'List databases Set objWshScriptExec = objShell.Exec(mysql &#38; &#34; --host=&#34; &#38; server &#38; &#34; -u&#34; &#38; user &#38; &#34; -p&#34; &#38; pw &#38; &#34; -e&#34;&#34;SHOW DATABASES&#34;&#34;&#34;) [&#8230;]]]></description>
										<content:encoded><![CDATA[<pre class="brush: vb; title: ; notranslate">

'MySQL Backup Script
'run with &quot;cscript mysql_backup.vbs&quot;

'Configuration
server = &quot;www&quot;
user = &quot;backup&quot;
pw = &quot;BackupPW&quot;
mysql = &quot;mysql.exe&quot;
mysqldump = &quot;mysqldump.exe&quot;
backupdir = &quot;e:mysqlbackupwww&quot;

Set objShell = CreateObject(&quot;WScript.Shell&quot;)

'List databases
Set objWshScriptExec = objShell.Exec(mysql &amp; &quot; --host=&quot; &amp; server &amp; &quot; -u&quot; &amp; user &amp; &quot; -p&quot; &amp; pw &amp; &quot; -e&quot;&quot;SHOW DATABASES&quot;&quot;&quot;)
Set objStdOut = objWshScriptExec.StdOut

Do Until objStdOut.AtEndOfStream
db = objStdOut.ReadLine

If db &lt;&gt; &quot;Database&quot; Then
filename = db &amp; &quot;_dump.txt&quot;
WScript.Echo &quot;dumping database &quot; &amp; db &amp; &quot; nach &quot; &amp; backupdir &amp; filename
objShell.Run mysqldump &amp; &quot; --routines=true --triggers=true --events=true --host=&quot; &amp; server &amp; &quot; -u&quot; &amp; user &amp; &quot; -p&quot; &amp; pw &amp; &quot; --result-file=&quot; &amp; backupdir &amp; filename &amp; &quot; &quot; &amp; db, 3, true
objShell.Run(&quot;c:zip_file_and_delete.bat &quot; &amp; backupdir &amp; filename &amp; &quot;.7z&quot; &amp; &quot; &quot; &amp; backupdir &amp; filename)
End If
Loop


</pre>
<p>&nbsp;</p>
<p>zip_file_and_delete.bat contains:</p>
<pre class="brush: powershell; title: ; notranslate">


%PROGRAMFILES%7-Zip7z a -t7z %1 %2
if errorlevel 1 goto :error
del %2
:error


</pre>
<p>&nbsp;</p>
<p>Install <a href="http://7-zip.org/">7-Zip</a> to use compression.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2012/06/mysqldump-and-vbscript-dump-all-databases-into-separate-files-with-compression/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
