Web & Software Developer

Archive for “MySQL Code”

MySQL commands and SQL queries to help you manage your MySQL databases and tables.

MySQL Command Line Cheat Sheet

These are my most often-used MySQL commands and queries. Connect to MySQL on the command line (replace USERNAME and YOURPASSWORD with your own): MySQL Databases List all databases on the command line: Create a database on the command line: Replace database_name, above, with your name of choice. Delete a database: Replace database_name, above, with the … Read more →

Reset MySQL root password in Ubuntu/Linux Command Line

These are the terminal commands to reset your MySQL password for your “root” user. This is useful if you forgot your MySQL password on your local LAMP server. This is a fix for errors like these: ERROR 1045: Access denied for user: ‘root@localhost’ (Using password: NO) ERROR 1045: Access denied for user: ‘root@localhost’ (Using password: … Read more →

Insert Data Array Into MySQL Table Using PHP

Updated to use MySQL transactions, prepared SQL statments, and bound parameters. This lets you insert data from a PHP array into your MySQL database table. It will insert multiple rows into the table, where each row will take values from one array element. Before inserting, you must prepare your data into an array consisting of … Read more →

Add a Field to Existing MySQL Table

Insert a field or column right after some existing field in an existing table in a MySQL database. Replace ‘feildname’ with the new field name which you want to add. Replace ‘existingfield’ with your existing field name (the new field will be inserted after this existing field).