java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x96\xA4\xE2\x9C…’ for column

When your application tries to store 4-byte Unicode characters in a MySQL database you may get the error rmessage

java.sql.SQLException: Incorrect string value: ‘\x..\x..\x..\x..\x..\x…’ for column

 

To store 4-byte Unicode characters in MySQL you need

  • a modern version of the database engine, version 5.5 or later,
  • set the column collation to COLLATE utf8mb4_unicode_ci in the database,
  • configure MySQL to use utf8mb4 in the character columns.

 

To set the default character set and server settings to utf8mb4

  1. Open the C:\ProgramData\MySQL\MySQL Server 5.x\my.ini file
  2. Under [client] add
    default-character-set = utf8mb4
  3. Under [mysql] set the value to utf8mb4 in line
    default-character-set = utf8mb4
  4. Under [mysqld] set the value to utf8mb4 in line
    character-set-server = utf8mb4
  5. Under [mysqld] add the lines
    character-set-client-handshake = FALSE
    character-set-server = utf8mb4
    collation-server = utf8mb4_unicode_ci

Restart the MySQL server

  1. Restart the MySQL database server for the changes to take effect
  2. in MySQL Workbench reconnect the database.

Change the schema of an existing database

  1. In MySQL Workbench connect to the database server,
  2. Right-click the database and select Alter Schema,
  3. Set the collation to utf8mb4_unicode_ci collation
  4. Click the Appy button to save the changes,
  5. Click the Apply button again to confirm the instructions,
  6. Click the Finish button to execute the script.

To check the database settings execute the SQL query in MySQL Workbench

use MY_DATABASE_NAME;
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

It should show

+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8mb4            |
| character_set_connection | utf8mb4            |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | utf8mb4            |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | utf8mb4_unicode_ci |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+

Repair and optimize all tables

Make sure you execute the mysqlcheck command to repair and optimize all tables to avoid silent update errors

On Windows

"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqlcheck" -u root -p --auto-repair --optimize --all-databases

The utility makes it easy to execute the repair and optimize commands for every table

# For each table
REPAIR TABLE table_name;
OPTIMIZE TABLE table_name;

The security database on the server does not have a computer account for this workstation trust relationship

Time to time Windows servers may lose the trust of the domain. When you try to log in with your domain credentials you get the dreaded message:

The security database on the server does not have a computer account for this workstation trust relationship

This can have many causes, and the most effective way to fix this is to detach and re-attach the server to the domain.

For security reasons the best if there are no local admin accounts on the Windows server, only domain accounts added to the Administrators group. If there is no local admin account on the server, how can we access it with the non-working domain accounts? When a Windows computer loses the trust of the domain there is no way to log into it with a domain account when the computer is connected to the network and has access to the domain controllers.

If the server is in your data center it is enough to unplug the network cables, the server cannot connect to the domain controller, and you can log in with the last cached password you used for the Administrator domain account.

How can we unplug the network cables from a cloud computer?

The Amazon Web Services (AWS)  Security Groups and Azure Network Security Groups (NSG) act as firewalls. Those control the inbound and outbound traffic rules.

To be able to access your Windows server, but prevent it to contact the domain controller, create a security group that contains all necessary inbound rules to access your Windows server with the remote desktop connection, but do not enable any outbound connections.

Open port 3389 for inbound traffic, but do not allow any outbound traffic.

  1. Change the security groups of the server

    1. Unselect the existing security groups to remove all other security groups from the server,
    2. Select the newly created recovery security group
  2. Use Remote Desktop to log into the server with your domain credentials you used the last time you logged into the server (it can be an earlier domain password). If you use stored credentials in your remote desktop client, enter your password again on the Windows login screen.
  3. Create a local administrator account, because once you remove the server from the domain, you will not be able to log into it with your domain account,
  4. To make sure the local administrator account credentials are correct, remote into the server with the local account,
  5. Change the security group back to the original one that enables outbound access to the domain controller,
  6. Remove the server from the domain by attaching it to a workgroup,
    1. Right-click This PC and select Properties
    2. On the Control Panel Home window select Advanced system settings
    3. On the Computer Name tab of the System Properties window click the Change… button
    4. In the Computer Name/Domain Changes window select the Workgroup radio button and enter WORKGROUP for the name of the workgroup
    5. Make sure you do these steps with the local admin account and click OK.
    6. Enter the credentials of a domain account that has enough rights to remove servers from the domain,
    7. Your server is out of the domain,
    8. Make sure again, you have a local admin account on the server and click OK,
    9. Click the Close button to continue,
    10. Make sure you have a local admin account with a known password, all your files are saved, and click the Restart Now button to restart the computer.

Remove the server from the domain controller database

To successfully add the server to the domain again, you need to remove the current entry of the server from the domain.

  1. Log into the domain controller,
  2. Open the ActiveRoles Console,
  3. Expand the Active Directory item, right-click the domain name, and select Find,
  4. in the Find drop-down select Computers, enter the name of the computer into the Name field and click the Find Now button,
  5. Right-click the name of the found computer and select Delete.

 

Add the server to the domain

  1. Using the local admin account log into the server,
  2. Follow the steps above to open the Computer Name/Domain Changes window,
  3. Select the Domain radio button, enter the name of the domain, and click OK,
  4. Enter the credentials of a domain account that has enough rights to add servers to the domain. Don’t forget to add the name of the domain in front of your username with a backslash.
  5. The server has been successfully added to the domain,
  6. Click OK to continue,
  7. Click the Close button to restart the computer.
  8. Click the Restart Now button to restart the computer.

SQL Server AWS RDS instance ALARM FreeableMemory <=... MB

The SQL database servers use the available memory for caching to speed up the database operation. If we do not restrict the SQL database server memory usage, the operating system will not have enough memory to run. This setting is also necessary for an AWS RDS instance, otherwise, you will get the alert

ALARM FreeableMemory <=… MB

In AWS we can specify the maximum SQL server memory dynamically, so every RDS instance type will leave enough memory for the operating system regardless of the size of the available memory size. in this example, we will leave 1.5 GB (1536 MB) memory for the operating system so the default 1024 MB free memory alarm will not sound.

DBInstanceClassMemory returns the total memory size in bytes, so we need to convert the value to MB, to be able to set the value of “max server memory (mb)” to the correct number.

If you use Terraform to create your RDS instance, create a script with the aws_db_parameter_group resource to create a Parameter Group in your AWS account. You need to execute it once, as all RDS instances will use the same group.

resource "aws_db_parameter_group" "default" {

  name = "max-server-memory"
  family = "sqlserver-se-12.0"
  description = "DBInstanceClassMemory"

  parameter {
    name = "custom-sqlserver-se-12-0"
    value = "SUM({DBInstanceClassMemory/1048576},-1536)"
    apply_method = "immediate"
  }
}

In the RDS instance creation script assign the Parameter Group to the RDS instance and increase the timeout of the create and delete operations to make sure Terraform waits during the creation and deletion process.

resource "aws_db_instance" "default" {
...
  # Add the Max Server Memory parameter group to the instance
  parameter_group_name = "custom-sqlserver-se-12-0"
...
  timeouts {
    create = "120m"
    delete = "120m"
  }
...
}

 

 

 

Terraform provider.aws: no suitable version installed

The new versions of Terraform do not contain all plugins after the application installation. When you try to access a provider the first time, Terraform may not be able to communicate with it.

* provider.aws: no suitable version installed
version requirements: “(any version)”
versions installed: none

To download the necessary plugins, initialize the Terraform script directory

terraform init

The command will instruct Terraform to get all referenced modules and download all necessary plugins.

 

 

Display all teams you belong to in GitHub

To get the information on all teams you are part of in Github

  1. Open a Terminal window
  2. Execute this command with your Personal Access Token
curl -H "Authorization: token YOUR_PERSONAL_ACCESS_TOKEN" https://api.github.com/user/teams

The returned JSON will display all information on the teams you belong to.

To generate a personal access token

See Create a Personal Access Token to use it as password in the Git client at Git configuration

Chef NoMethodError, undefined method

When you try to bootstrap a node to a Chef server, you may get the error message

Compiling Cookbooks…
==============================================================
Recipe Compile Error in c:/chef/cache/cookbooks/…/attributes/default.rb
==============================================================
NoMethodError
————-
undefined method `…=’ for #<Chef::Node::VividMash:0x0000000004ca3268>

Relevant File Content:
>> default. …

In my case, the cookbook compiler could not interpret the dot notation in the recipes.

There are multiple ways to declare and use the Chef attributes:

default['ATT_NAME']

default["ATT_NAME"]

default[:ATT_NAME]

default.ATT_NAME

The last format, the dot notation is a legal form, but not accepted by the compiler that checks the cookbooks during bootstrapping. The same cookbook works perfectly in Test Kitchen, and in chef-client.

The solution is to change the dot notation to one of the other formats, preferably to the first in the list above.

 

Package dependent Java JAR files into the project JAR file

When you execute your Java JAR file, you need to include all dependent JAR files in the “fat jar” file, so the Java virtual machine can find them at runtime.

Set up NetBeans to include the JAR files from the library

In NetBeans you need to add the list of dependent libraries to the build.xml file.

  1. On the Files tab double-click the build.xml file to open it in the editor,
  2. Add the lines below to the build.xml file before the </project> statement. Change the value of the second line to specify the name of your project.
    <target name="package-for-store" depends="jar">
        <property name="store.jar.name" value="MY_PROJECT"/>
        <property name="store.dir" value="store"/>
        <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
        <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
        <delete dir="${store.dir}"/>
        <mkdir dir="${store.dir}"/>
        <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
            <zipgroupfileset dir="dist" includes="*.jar"/>
            <zipgroupfileset dir="dist/lib" includes="*.jar"/>
            <manifest>
            <attribute name="Main-Class" value="${main.class}"/>
            </manifest>
        </jar>
        <zip destfile="${store.jar}">
            <zipfileset src="${store.dir}/temp_final.jar"
            excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
        </zip>
        <delete file="${store.dir}/temp_final.jar"/>
    </target>
  3. Save the build.xml file.

Build the project

  1. Right click the build.xml file,
  2. Select Run Target > Other Targets > package-for-store
  3. The generated file is going to be located in the store directory.

Restore Windows Server 2012 R2 from backup

Windows Server contains the Windows Backup functionality. It can create full backups of your server that contain all volumes. With the bare metal recovery, you are able to fully restore the server even if the hard disks fail, after a virus attack, or security breach. Depending on the size of the server drives and the backup media, set up frequent backup times, so when you need to restore the server, less data has to be entered again.

To restore a Windows Server from a backup image

  1. Insert the Windows Server 2012 R2 installation DVD into the DVD drive of the server
  2. Boot the server from the DVD
  3. Connect the drive, that contains the backup images, to the server
  4. On the first screen select the language and keyboard options
  5. On the next screen, select Repair  your computer
  6. Select the Troubleshoot icon
  7. Click the System Image Recovery
  8. Select your operating system as the target operating system
  9. Select the backup image to restore; latest or from a previous date
  10. If you selected Select a system image option
    1. In the table select the backup device
    2. Select the time of the backup
    3. If you want to clear the drives of the server select the Format and repartition disks option

Tomcat web server installation

Tomcat is one of the most popular free web servers. Tomcat runs on the Linux, Macintosh, and Windows operating systems.

To install Tomcat

Install the Java Runtime Environment (JRE)

  1. Download the Java JRE from http://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. Install the Java JRE

On Windows

  1. Execute the downloaded .exe file
  2. Create an environment variable to point to the installed Java
    1. If you installed the Java JDK (Java Development Kit)
      1. JAVA_HOME=c:\Program Files\Java\jdk-…
    2. If you installed the JRE (Java Runtime Environment)
      1. JRE_HOME=C:\Program Files\Java\jre-…

 

Install Tomcat

  1. Download the Tomcat installer from https://tomcat.apache.org/
  2. To select the right file to download read the explanation on the page linked to “Please see the README file for packaging information”.

On Windows

Select the installer based on the operating system and the Java environment you want to run:

  • 32 bit Java Virtual Machine on32 bit or 64 bit Windows: apache-tomcat-[version]-windows-x86.zip
  • 64 bit Java Virtual Machine on 64 bit Windows: apache-tomcat-[version]-windows-x64.zip
  1. Unzip the downloaded archive and move the apache-tomcat-x.x.x directory to C:\Program File
  2. Create the Tomcat environment variable
    CATALINA_HOME=C:\Program Files\apache-tomcat-x.x.x

Start Tomcat

  1. Open a terminal or console in the Tomcat bin directory
  2. Execute
    startup
  3. Enable the access to the Tomcat server through the firewall
    1. On Windows

Test Tomcat

  1. Open a web browser on the server and navigate to http://localhost:8080/
  2. You should see the Tomcat default page

Auto start Tomcat

If you want to use Tomcat as a web server, it should start automatically when the computer starts.

On Windows

  1. Open a command prompt in the tomcat bin directory
  2. Execute
    service.bat install
  3. On the User Account Control popup click the Yes button
  4. The last message in the command prompt should say

    The service ‘Tomcat..’ has been installed.

  5. Open  Services and select the Apache Tomcat service
  6. Set the Startup type to Automatic, click the Start button to start the service, and click OK.

 

Enable Single Sign-On (SSO) in TeamCity

Enable Single Sign-On (SSO) in TeamCity

TeamCity can use the Windows Active Directory to authenticate users. To configure TeamCity to automatically log in users who are already logged into the Windows domain enable the Single Sign-On (SSO) functionality.

  1. In the upper right corner of the TeamCity web interface select Administration,
  2. On the left side in the Server Administration section select Authentication,
  3. Under HTTP authentication modules click the Load preset… button,
  4. In the drop-down list select Microsoft Windows Domain,
  5. Click the Edit link of the Microsoft Windows domain,
  6. Enter the name of the domain in your organization. If you leave the Allow creating new users… checkbox enabled, when new users log into TeamCity they are placed into a default user role. Make sure that role does not give them any authority.

Accessing TeamCity using Single Sign-On (SSO)

  1. With your web browser navigate to MY_TEAMCITY_SERVER/ntlmLogin.html,
  2. If asked, enter your domain username and password once,
  3. Subsequent logins in the same browser will not require authentication while the browser stays open.