Knebel Home
{ MySQL }
Add a new MySQL user
Here's how to create a new MySQL user. This user will need to be given privelages to your tables and databases at a later time.
Batch files in mysql
This is the command for executing a batch file in mysql. To run manually, you can use the mysql command-line, then type the code below (note: this example is on windows platform - change the slashes for i/ux)
Change a field in your table into a unique ID field
Do you have a field that you exported into MySQL, which didn't come out as a unique id? Here's how to change that:
Change Column (Field) Parameters
Let´s say you want to lengthen one of your MySQL fields. Here´s how to do it: Here, we are changing the field length to 20 (no matter what the previous length was).
Character Returns with PHP
ISSUE: Carriage returns going in, turn out on 1 line when displayed. RESOLUTION: Format your line breaks by replacing "/n" with ´< br >´ and on the way out, do the reverse: Take a look:
Comments in MySql
Use the following syntax to include comments in your SQL code for MySql: #xyz OR /* xyz */
Concatenating Strings in MySql
This example shows you how to concatenate strings in your MySql Select Statements.
Convert special characters for insertion into MySQL
Here is the context (ereg_replace) you need to use when converting quotes, and other special characters when inserting into a MySQL database.
Create Table Syntax for MySQL
Here´s how to create a table in MySQL with a unique, autonumber id, and somefield.
Disable STRICT mode
Here's how to disable Strict mode in MySql. This can be useful when working with bulk inserts whose data doesn't explicitly comply with existing DB format.
Disable STRICT mode
Here's how to disable Strict mode in MySql. This can be useful when working with bulk inserts whose data doesn`t explicitly comply with existing DB format.
Get records by their position in the recordset.
So, you want to get records 1-5, or 5-10, but not the others? (Good for paging!) It&acute;s in the query. Here is how you will do it:
Get values from a result set w/o looping (e.g. grab the first (or x) record)
Obtain field values without looping through rows (useful, for example, if you only need the first record).
Grant User Rights Syntax
Grant privelages to your MySQL users with the following syntax. Common functions(privelages) include: ALL PRIVILEGES FILE RELOAD ALTER INDEX SELECT CREATE INSERT SHUTDOWN DELETE PROCESS UPDATE DROP REFERENCES USAGE
MySql database dump
drop this into a batch file (.bat) and schedule it to run.  it will create a backup and error log of your mysql database.
MySQL System Functions
Here are some useful functions for obtaining information about MySQL. Most examples are in PHP.
Resetting Auto-Incrementing Fields
This SQL code will reset the auto-incrementing field back to 1
Restart MySql service in Windows (Vista, XP, 2k, NT)
Restarting the Windows MySql service is very simple. Simply open up a command prompt (as administrator), and type the following:
Returning MySQL records by time interval
Use the following syntax to retrieve records from MySql, when you need to match a date interval by number of days.
Timestamp to YYYY-MM-DD format
Use the following to return a timestamp (tstamp in this case) field in YYYY-MM-DD HH:MM:SS format.
Transactional MySql in PHP
Run MySql Transactions from PHP Here's how you can run multiple queries, and rollback the transaction on failure of any single query.
Using DATE_FORMAT() to return a formatted date
DATE_FORMAT() allows you to format the output from within a SQL statement in MySql.