mysql
How to run multiple sql statements at once from the command line
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
- liviu's blog
- Login or register to post comments
- Read more
How to see what mysql is doing - what processes are running
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.
- liviu's blog
- Login or register to post comments
A smart search for mysql - full text search
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.
- liviu's blog
- Login or register to post comments
mysql: How to see what field repeats itself in a table
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;
- liviu's blog
- Login or register to post comments
How to import and export a mysql database from the command line
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
- liviu's blog
- Login or register to post comments
- Read more
Querying a mysql database with php example
This example was taken from
| Programming PHP, 2nd Edition | ||
| By Rasmus Lerdorf, Peter MacIntyre, Kevin Tatroe | ||
| ............................................... | ||
- liviu's blog
- Login or register to post comments
- Read more
How to speed up your mysql queries
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:
- liviu's blog
- Login or register to post comments
- Read more
mysql: How to see how many elements a result has
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)) {
......
}}
- liviu's blog
- Login or register to post comments
How to get the id of an inserted mysql row in php
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 ] )
- liviu's blog
- Login or register to post comments
- Read more
Why aren't my line breaks from the form showing when I display data from the database
Why aren't my line breaks from the form showing when I display data from the database?
I ran into this a year ago, when i was building my first community site in php from the ground up. I formatted the data to look ok in the form, but when i fetched the data from the database and echoed it on the page, all the line breaks were gone. It looked horribly. In phpmyadmin it looked good thou.
- liviu's blog
- Login or register to post comments
- Read more