Category Archives: MySQL

Linux server – start/stop/restart mysql

Its merely a reminder so i dont go through the search to restart mysql on one of my stupid servers: Usually (i think) its like this: /etc/init.d/mysqld start /etc/init.d/mysqld stop /etc/init.d/mysqld restart On that server of mine, because of some config: /etc/rc.d/init.d/mysqld start /etc/rc.d/init.d/mysqld stop /etc/rc.d/init.d/mysqld restart

Find duplicate records in SQL table

There are a few ways to do this, but i am leaving this one here so its easy to find. SELECT nome, COUNT(nome) FROM Patrimonio GROUP BY nome HAVING ( COUNT(nome) > 1 ) This returns a list with two columns of records that exist in table “Patrimonio” more than once. A column for “nome”… Read More »

PHPMaker characters encoding problem

Its the second time i run across this issue with PHPMaker. Its not exactly the problem’s fault, more a config issue. I havent completely assessed all details on this issue, since i dont have complete access to the server i mention. I just want to leave this so next time something like this happens, i,… Read More »

update table with values from other table

I ran into a problem where i had to update two values on a table. One was fixed, but the other depended on a value stored on a second table. This is how its done. TableA id_cli   test_cut 1          15 2          56 TableB id    num_of        job    test_cut    id_client 1     20090464    34      0               2 2    … Read More »

Compare two tables/fields

Found this somewhere on google. If we need to compare two tables, this query will list the missing records on one of them (on table2): SELECT t1.id FROM table1 t1 LEFT JOIN table2 t2 ON t1.id = t2.id WHERE t2.id IS NULL Then you do it the other way around to check the mising records… Read More »

MySQL Command Line – Part 1

This is a simple reminder of the mysql command line tool. In windows, open a command line, navigate to mysql binary folder (if you have it on your PATH, you can skip the navigation part), and use: To login: mysql -u #username# -p#password# (if you dont add the #password#.. it will ask you for one.… Read More »

update table with join condition from different table

If we want to make an update to a table, but have to condition that update with values from a second one, we do something like this: TABLE_1 id_t1 name fee 1 john 100 2 rita 100 3 peter 100 TABLE_2 id_t2 id_t1 type 1 1 single 2 2 single 3 3 married If we… Read More »

insert into table from a second table

Its simple but i thought of leaving it here if i forget (which is usually the case) how to do it again. If you want to insert the records from tableA into tableB, you do something like this: INSERT INTO tableA SELECT * FROM tableB You have to make sure all fields are the same… Read More »