I found a very handy SQL script on this post, that allows you to enable or disable all constraints on a database. The only problem I had was that my database uses schemas to organize the tables, so the script failed to work.
I made a modification on the script to solve the problem, so here it is:
/************************** DISABLE ALL TABLE CONSTRAINTS **********************************
This script will enable or disable all constraints on all tables within the database
that it is run in.
********************************************************************************************/
SET NOCOUNT ON
SET ROWCOUNT 0
DECLARE @COUNT INT
DECLARE @String nvarchar (1000)
DECLARE @ConstraintName VARCHAR(128)
DECLARE @TableName VARCHAR(128)
DECLARE @SchemaName VARCHAR(128)
--Find all constraints and their respective tables from the sysobjects table and place into a temp table.
--Primary Key and Unique Constraints via Unique Indexes are not disabled through this command
--You should use the ALTER INDEX...DISABLE command in SQL Server 2005
SELECT
o.name AS ConstraintName,
sc.name AS SchemaName,
object_name(o.parent_obj) AS TableName
INTO #Const_Table
FROM sysobjects o, sys.schemas sc
WHERE xtype IN ('F') AND o.uid = sc.schema_id
SELECT @COUNT = COUNT(*) FROM #Const_Table
--Setting the rowcount to one allows for one row from the temp table to be picked off at a time.
--Used as an alternative to a cursor.
SET ROWCOUNT 1
--Loop until all rows in temp table have been processed.
WHILE @COUNT > 0
BEGIN
--The rowcount of one ensures that only one tablename and constraint name is picked.
SELECT @TableName = TableName, @SchemaName = SchemaName, @ConstraintName = ConstraintName
FROM #Const_Table
--Comment or uncomment the following statements according to your needs
--Build execution string to enable constraint.
SET @String = 'ALTER TABLE ['+ @SchemaName + '].['+ @TableName + '] WITH CHECK CHECK CONSTRAINT [' + @ConstraintName +']'
--Build execution string to disable constraint.
--SET @String = 'ALTER TABLE ['+ @SchemaName + '].['+ @TableName + '] NOCHECK CONSTRAINT [' + @ConstraintName +']'
--Execute the SQL
EXEC sp_executesql @string
--Remove this row from the temp table, since it has now been processed.
DELETE FROM #Const_Table
WHERE ConstraintName = @ConstraintName AND TableName = @TableName AND SchemaName = @SchemaName
SET @COUNT = @COUNT - 1
END -- Loop
DROP TABLE #Const_Table
SET ROWCOUNT 0 |
/************************** DISABLE ALL TABLE CONSTRAINTS **********************************
This script will enable or disable all constraints on all tables within the database
that it is run in.
********************************************************************************************/
SET NOCOUNT ON
SET ROWCOUNT 0
DECLARE @Count int
DECLARE @String nvarchar (1000)
DECLARE @ConstraintName varchar(128)
DECLARE @TableName varchar(128)
DECLARE @SchemaName varchar(128)
--Find all constraints and their respective tables from the sysobjects table and place into a temp table.
--Primary Key and Unique Constraints via Unique Indexes are not disabled through this command
--You should use the ALTER INDEX...DISABLE command in SQL Server 2005
SELECT
o.name AS ConstraintName,
sc.name AS SchemaName,
object_name(o.parent_obj) AS TableName
INTO #Const_Table
FROM sysobjects o, sys.schemas sc
WHERE xtype in ('F') AND o.uid = sc.schema_id
SELECT @Count = Count(*) FROM #Const_Table
--Setting the rowcount to one allows for one row from the temp table to be picked off at a time.
--Used as an alternative to a cursor.
SET ROWCOUNT 1
--Loop until all rows in temp table have been processed.
WHILE @Count > 0
BEGIN
--The rowcount of one ensures that only one tablename and constraint name is picked.
SELECT @TableName = TableName, @SchemaName = SchemaName, @ConstraintName = ConstraintName
FROM #Const_Table
--Comment or uncomment the following statements according to your needs
--Build execution string to enable constraint.
SET @String = 'ALTER TABLE ['+ @SchemaName + '].['+ @TableName + '] WITH CHECK CHECK CONSTRAINT [' + @ConstraintName +']'
--Build execution string to disable constraint.
--SET @String = 'ALTER TABLE ['+ @SchemaName + '].['+ @TableName + '] NOCHECK CONSTRAINT [' + @ConstraintName +']'
--Execute the SQL
EXEC sp_executesql @string
--Remove this row from the temp table, since it has now been processed.
DELETE FROM #Const_Table
WHERE ConstraintName = @ConstraintName AND TableName = @TableName AND SchemaName = @SchemaName
SET @Count = @Count - 1
END -- Loop
DROP TABLE #Const_Table
SET ROWCOUNT 0
To count the total number of records on a MySQL database, we could run the following command:
SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{tablename}'; |
SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{tablename}';
If we need to know the number of records per each table, we can run:
SELECT TABLE_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{tablename}'; |
SELECT TABLE_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{tablename}';
Source: Stack Overflow
On this article, it is shown a very convenient way to duplicate a complete MySQL database using a single line of code:
$ mysqladmin create {dest_db_name} -u {username} --password={password} && \
mysqldump -u {username} --password={password} {source_db_name} | \
mysql -u {username} --password={password} {dest_db_name} |
$ mysqladmin create {dest_db_name} -u {username} --password={password} && \
mysqldump -u {username} --password={password} {source_db_name} | \
mysql -u {username} --password={password} {dest_db_name}
Where:
- {dest_db_name}: Name of the destination database.
- {source_db_name}: Name of the database to be duplicated.
- {username}: MySQL username.
- {password}: MySQL password.
If we need to duplicate it to another server, we would do something like this:
$ mysqladmin create {dest_db_name} -u {dest_username} --password={dest_password} -h {dest_server} && \
mysqldump -u {source_username} --password={source_password} -h {source_server} {source_db_name} | \
mysql -u {dest_username} --password={dest_password} -h {dest_server} {dest_db_name} |
$ mysqladmin create {dest_db_name} -u {dest_username} --password={dest_password} -h {dest_server} && \
mysqldump -u {source_username} --password={source_password} -h {source_server} {source_db_name} | \
mysql -u {dest_username} --password={dest_password} -h {dest_server} {dest_db_name}
Where:
- {source_db_name}: Name of the source database.
- {source_server}: Source MySQL server.
- {source_username}: Source MySQL username.
- {source_password}: Source MySQL password.
- {dest_db_name}: Name of the destination database.
- {dest_server}: Destination MySQL server.
- {dest_username}: Destination MySQL username.
- {dest_password}: Destination MySQL password.
To be allowed to show Nginx graphs on the Munin report, it is required to enable nginx status and to listen on:
http://127.0.0.1/nginx_status
To do this, we just need to add the following code on /etc/nginx/sites-enabled/default or into any other site file (like create a new one /etc/nginx/sites-available/status and then make symbolic link to site-enabled directory):
server {
listen 127.0.0.1;
server_name localhost;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
Source: Server Fault
Today, I decided to try the VMWare ESXi, the free bare metal virtualization product of VMWare, on an old Pentium 4 3.2GHz PC (with 2.5GB of RAM), and run on top of it, some Ubuntu servers.
I was not able to use the latest version (4.x) of the ESXi as it only works on 64-bit boxes. Instead, the version 3.5 does work on 32-bit processors as the one I’m using.
As I didn’t want to burn a CD with the installer, I chose to use an USB stick to make the installation. So, the first thing to do was converting the ISO installer into a USB, using this software. I had a little problem, that I solved in some minutes with the help of Google.
After that, the installation ran without problems (there is a nice ESXi installation guide here) and the server was up and running some minutes later.
Then, I just unplugged the monitor, keyboard and mouse from that PC, as they are not gonna be needed anymore. I installed the VMWare vSphere Client on my main machine to manage the server.
So far, I have installed two Ubuntu Linux servers and they are running with not bad performance, at least, enough for testing and development.
When I tried to run the VMWare ESXi installer from a USB stick (after creating the installer on a USB from the ISO), I got the following error:
SYSLINUX 3.85 2010-02-20 CBIOS Copyright (c) 1994-2010 H. Peter Anvin et al
No DEFAULT or UI configuration directive found!
boot:
The solution was pretty simple thanks to this post. I just needed to rename a couple files on the USB as follows:
- isolinux.bin to syslinux.bin
- isolinux.cfg to syslinux.cfg
It worked flawless. But if that does not work for you, you may try formatting the USB as FAT instead of FAT32.
posts.forEach(post => document.write(post))