Tuesday, 19 May 2020

MySQL: Fix Error 1071 "Specified key was too long"

MySQL/MariaDB Error 1071 when try to import SQL File:

#1071 - Specified key was too long; max key length is 767 bytes
Sometime error is "max key length is 1000 bytes"

Reason:
From MySQL 5.6 and MariaDB 10.2.2 InnoDB File Format default is Barracudar. Barracudar is newer file type ,support many new format types (DYNAMIC and COMPRESSED). But in older version of MySQL or MariaDB default InnoDB File Format is still Antelope. So if you want to import a database using Barracudar(exported from newer version), you also need to change the current file format to Barracudar.

Solved:
To do that, run the following command in the Mysql command line (Root account is required):

SET GLOBAL innodb_file_format = Barracuda;
SET GLOBAL innodb_file_per_table = on;
SET GLOBAL innodb_default_row_format = dynamic;
SET GLOBAL innodb_large_prefix = 1;
SET GLOBAL innodb_file_format_max = Barracuda;
FLUSH PRIVILEGES;
Done ! The problem has been solved, you can try imoport SQL file again.

Tip: You can run Mysql command line from linux terminal or run Query in Navicat, PHPMyadmin ....

mysql -h localhost -u root -p
Refer: https://dev.mysql.com/doc/refman/5.6/en/innodb-file-format-enabling.html

Thursday, 14 May 2020

Git: How to fix Error Pulling is not possible because you have unmerged files



If you try to pull new code while some local files have been changed without commit, you will get this error.

Error Pulling is not possible because you have unmerged files.
or
Error: Your local changes to the following files would be overwritten by merge
To fix it you have 2 options:

* Method 1: Commit the changes, then pull the new code
- Add new files if available
git add filename1.xyz folder/filename2.xyz  
or (add all new file)
git add -A    
- Commit new changes

git commit -m "Add new file or something need to noted"
* Method 2: Remove all local changes to update new code
(We often encounter this situation on the server)
To do so, run the following command:

git reset --hard origin/master
- note: 'master' is the name of the branch you want to update new code from that.

Done ! Now we can update new code by git pull command.

git pull




Friday, 8 May 2020

MongoDB: Error Unsupported mechanism SCRAM-SHA-256


Studio 3T Fix Error 2 "Unsupported mechanism SCRAM-SHA-256" when try to connect to server.

Cause: 
MongoDB only supports SCRAM-SHA-256 for authenticating users with passwords from MongoDB version 4.0. So if you encounter this error, you can try to switch back to the SCRAM-SHA-1 method.

More about MongoDB SCRAM supports :
MongoDB >= 4.0 Support SCRAM-SHA-1 and SCRAM-SHA-256
MongoDB 3.x Support only MONGODB-CR and SCRAM-SHA-1
MongoDB <3.0 Support only MONGODB-CR

Thursday, 7 May 2020

Composer: How to fix error "Fork failed errors" in Linux server


In many cases we encounter lack of memory errors when running "composer install" or "composer update" command to update packages in our PHP project.
Some of the error messages you may receive:

  • - proc_open(): fork failed errors - Cannot allocate memory
  • - exception is caused by a lack of memory
  • - Killed

The cause of all these errors is because our server does not have enough RAM to allocate to Composer. Increasing packages in the project, the larger the size, so this error is also becoming more and more common. To fix them you can increase the server's physical RAM but the cost will be quite expensive.

There is another solution simpler and completely free to fix Composer memory error. That is we can enable swap space for the server. This is quite easy to implement and will thoroughly fix the error we encounter. For each operating system, there will be different ways to initialize swap partitions. You can refer to one of the instructions below:

Enable Swap to fix Composer memory error for Centos, Ubuntu ...:

Step 1: Create a new Swap file (1GB to 3Gb)
sudo fallocate -l 3G /swapfile
Step 2: Add Write permission for Swap file
sudo chmod 600 /swapfile
* If your server is running under SELinux, after chmod command you must run the following command
sudo chcon -t swapfile_t /swapfile 
Step 3: set up a Linux swap area
sudo mkswap /swapfile
Step 4: Active Swap for server
sudo swapon /swapfile
opening the "/etc/fstab" file
vi /etc/fstab
then add the following line at end of file.
/swapfile swap swap defaults 0 0

Done ! If there are no errors, you have successfully enabled the swap for your server. You can try checking the swap partition with one of the following commands:
sudo swapon --show
or
top
or
sudo free -h

Now it's time to try running the composer commands again. Hopefully the bug has been fixed. Good luck.

*Note:
- /swapfile  - is file name for swap file, you can use another name or put it in another folder.
- In addition to using swap files, you can also try to use swap partitions.
- Some problems with PHP modules can also cause errors because Composer runs on PHP

*Refer: https://getcomposer.org/doc/articles/troubleshooting.md