mysql

Mysql - get multiple values at once - group_concat

Tagged:  

If you want to get values for a column in one field of a return result row, you can always use group_concat

You can find some examples here and here like:

SELECT id,GROUP_CONCAT(client_id) FROM services WHERE id = 3 GROUP BY id;

How to run multiple sql statements at once from the command line

Tagged:  

In case you have to work from the command line (ssh?) and you need to run a lot of queries, instead of just running them one by one you can put your sql statements (inserts, updates, queries or whatever) and use:

shell> mysql db_name < text_file

If you have "use db_name" as your first line in your text_file you can just youse
shell> mysql < text_file

If you are in mysql you can use:
mysql> source file_name

How to see what mysql is doing - what processes are running

Tagged:  

If you wanna see what the mysql server is doing you can use mysql administrator from the mysql gui tools. It's a verry nice utility.
To find it google search for mysql downloads and download mysql gui tools. There you can find the mysql administrator.

A smart search for mysql - full text search

Tagged:  

Mysql has something called full text search, that returns results by relevance. Kind of like google does. The downside is that it can only be used on MyISAM tables, which unlike InnoDB tables, lock the entire table when it's being written to, instead of locking only a row.
For a table that is very ofter being written and read from that could be hard to take.

mysql: How to see what field repeats itself in a table

Tagged:  

I liked this query a lot so i wanted to remember it.It's simple but pretty cool:select column, count(column) as numfrom tablegroup by column having num > 1;

How to import and export a mysql database from the command line

Tagged:  

Sometimes you need to use the command line to export or import a mysql database.
Here is how you do it:

mysqldump -u theUser -p theDataBaseName > /path/to/dump/to/export.dump

mysql -u theUser -p theDataBaseName < /path/to/dump/to/import.dump

Querying a mysql database with php example

Tagged:  
This example was taken from 
Programming PHP, 2nd Edition
By Rasmus Lerdorf, Peter MacIntyre, Kevin Tatroe
...............................................

How to speed up your mysql queries

Tagged:  

Ran into this while reading Ubuntu Linux Unleashed, 2008 Edition. It's a great book about linux mainly, but also has some basics about mysql, apache, php, pearl, python and some other goodies (definitely worth buying of you are a programmer and wanna get into linux).

At some point it had some tips on how to optimize queries in mysql:

mysql: How to see how many elements a result has

Tagged:  

To see how many elements a mysql result has in php you use mysql_num_rows like so:
 
$query="select * from news where a=1 order by id desc";$result=mysql_query($query);if (mysql_num_rows ($result) == 0){  echo 'no news has been added yet'
}
else {  while($row=mysql_fetch_array($result))    {
       ......
    }}

How to get the id of an inserted mysql row in php

Tagged:  

This saved me a lot of work after i found out about it. After you insert a row in a mysql table, you can get the id that was automatically created using this php funtion: mysql_insert_id ([ resource $link_identifier ] ).

mysql_insert_id — Get the ID generated from the previous INSERT operation

int mysql_insert_id ([ resource $link_identifier ] )

Syndicate content