Fix / SET autoincrement in postgresql

Updated: 4th November 2024
Tags: sql postgresql

[postgresql only] Fix users table’ autoincrement

select setval('users_id_seq', coalesce(
(select max(id)+1 from users), 1), false)

[postgresql only] Manually set next autoincrement id of users table to 100:

setval('users_id_seq', 100)

MySQL remove duplicate rows

Updated: 17th November 2023
Tags: mysql sql

mysql str_replace

Updated: 4th February 2023
Tags: mysql sql
UPDATE my_table SET column1 = REPLACE(column1, 'search string', 'replacement');

How to change auto_increment mysql

Updated: 9th January 2023
Tags: sql mysql
ALTER TABLE my_table_name AUTO_INCREMENT = 777;

How to find where MySQL data is being stored

Updated: 6th December 2022
Tags: sql mysql

bash

mysql -e "show variables like 'datadir'"

mysql

show variables like 'datadir'

MySQL Fix login for phpmyadmin

Updated: 24th December 2019
Tags: sql mysql

[Solved] MySQL ERROR 1231 (42000):Variable 'character_set_client' can't be set to the value of 'NULL'

Updated: 24th December 2019
Tags: sql mysql

If you try to import dumped file, and there is such an error, try using mysql console with options and then import sql file

mysql -u root -p --max_allowed_packet=6400M

Troubleshoot

If you haven’t acess to console or the previous doesn’t work

set global max_allowed_packet=10000000000;

PHP Simple PDO class

Updated: 23th December 2019
Tags: php mysql sql

SQL select latest row from table

Updated: 22th December 2019
Tags: sql
SELECT * FROM my_table ORDER BY id DESC LIMIT 1;

SQL select max id from table

Updated: 22th December 2019
Tags: sql
SELECT MAX(id) FROM my_table;

Laravel select random row from table

Updated: 22th December 2019
Tags: php laravel sql

Get randow row from table in laravel 5.3+

$randomRow = DB::table('table')
            ->inRandomOrder()
            ->first();

Get randow id from table in laravel 5.3+

$randomId = DB::table('table')
            ->inRandomOrder()
            ->value('id');

How to be friend with mysql timestamp

Updated: 22th December 2019
Tags: sql mysql

SQL select random row from table

Updated: 22th December 2019
Tags: sql
SELECT * FROM my_table ORDER BY RAND() LIMIT 1;