Позднее Ctrl + ↑

How to set the MySQL root password in the Debian 9 (or MySQL 5.7+, MariaDB 10.1+)

You can think that there is no problem to set the root password in installation time. It’s true until 5.7 version of MySQL (or MariaDB 10.1). Now you can be authorized under root (and without password), but only through the auth_socket. For example, authorization under root in mysql-client:

mysql -u root

It means that the phpMyAdmin or other scripts will not be able to use root access more.

Now the next methods do not work:

mysqladmin -u root password
SET PASSWORD FOR root@localhost=PASSWORD, UPDATE user SET Password=PASSWORD

What can we make to use root privileges as earlier? We can create new user with root privileges and use it. Let’s do that.

First step:

mysql -u root

Create new a user with root privileges:

CREATE USER 'root2'@'localhost' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'root2'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Where root2 and PASSWORD change to what you want.

Therefore the following command can be useful to you for giving privileges to users through mysql-client:

GRANT ALL PRIVILEGES ON `DB_NAME`.* TO 'DB_USER'@'localhost';

Where DB_NAME and DB_USER change to what you want again.

 115   2019  

How to import big MySQL dump quickly

Warning: This trick is only for InnoDB storage engine.

Open MySQL config file “/etc/mysql/my.cnf”:

mcedit /etc/mysql/my.cnf

Write into [mysqld] section:

[mysqld]
...
innodb_flush_log_at_trx_commit = 2

What does that mean? Now, data will be recorded not more often than once per second! It will very unload file system and increase speed of import.

But you need check that you haven’t this option:

...
general_log = 1
...

Because everything will be worthless with that option! Every SQL query will be written on the disk and import will be worked slowly.

You need to disable “slow_query_log” if it enabled too.

Well, if you don’t have that options or you have deactivated it, for the next step you need to restart the database server:

service mysql restart

I have to notice you, if your dump archived in gzip, you need to unpack it and import only raw dump! Because unpacking on the fly and importing at the same time works slowly.

So, let’s import:

mysql -u username -p db_name < dump.sql

After all don’t forget to delete or restore “innodb_flush_log_at_trx_commit” option from config “/etc/mysql/my.cnf” and reload mysql server!

Sources: ruhighload and mysql.com.

 101   2019  

Fix issue with “Insert the picture” button in the Summernote

Summernote deactivates “Insert the picture” button when you use the context menu by mouse to insert the link.

You can use next code to fix this issue:

$('body').on('paste', '.note-image-url', function(e) {
    $('.note-image-url').val(e.originalEvent.clipboardData.getData('text'));
    $('.note-image-btn').removeAttr('disabled').removeClass('disabled');

    return false;
});
 118   2019  

Fix: the text hides under the toolbar in Summernote

If you put several Summernote editors in Bootstrap tabs, then after navigating between tabs, the text in the editor hides under the toolbar. At the same time it is enough to scroll the page down or up and then everything falls into place.

We as users can patch it:

$('.yourSelector[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    $('.note-editor').scroll();
});
 151   2019  

Fix: Option “disableDragAndDrop: true” doesn’t works in Summernote

In my case, this option doesn’t works:

$('.editorField').summernote({
    ...,
    disableDragAndDrop: true // Не работает...
});

I think it is a summernote bug. Maybe it will be fixed in new versions or it has already fixed, but I don’t want to update editor now. Therefore I made a dirty hack in my code:

$('body').on('drop', '.note-editable', function() {
    return false;
});
 104   2019  

How to remove records from active connections and ip_conntrack by IP

Someone can opens hundreds tabs with autoupdate pages in browser and make lot of persistent open connections to the server. If you want to drop his connections, you have to find him at first:

sudo cat /proc/net/ip_conntrack | grep 'ESTABLISHED' | wc -l
sudo cat /proc/net/ip_conntrack | grep 'ESTABLISHED'
netstat -tulpan | grep 'ESTABLISHED' | wc -l
netstat -tulpan | grep 'ESTABLISHED'

If you found a lot of connections from one IP, check it: (Replace 255.255.255.255 to necessary IP)

sudo cat /proc/net/ip_conntrack | grep 'ESTABLISHED' | grep '255.255.255.255' | wc -l
netstat -tulpan | grep '255.255.255.255' | wc -l
whois 255.255.255.255

Look to the web server logs whether the activity is suspicious:

cat /var/log/nginx/access.log | grep '255.255.255.255'

Then drop user connections:

sudo cutter 255.255.255.255
sudo conntrack -D conntrack --orig-src 255.255.255.255
sudo cat /proc/net/ip_conntrack | grep '255.255.255.255' | wc -l
sudo cat /proc/net/ip_conntrack | grep 'ESTABLISHED' | wc -l
 182   2019  
 115   2019  
 223   2018  

How to setup composer globally

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/bin --filename=composer
php -r "unlink('composer-setup.php');"
 150   2018  
 151   2018  
Ранее Ctrl + ↓