Mysql Cheat Sheet

Logon:
From local host: mysql
With password: mysql -u username -ppassword

Database:  show databases;
  create database dbname;
  use database dbname;

Tables: show tables;
Create:

create table tablename (id char(2), date DATE, norooms INT(5)); Documentation

 

Example, including key and auto-increment create table requests (id int auto_increment, name char(255), business char(255), primary key (id));
  create table events (id int(11) not null auto_increment, title varchar(50), loc varchar(50), desc1 char(255), desc2 char(255), url char(100), directions char(255), address char(255), phone char(100), primary key (id));
Information: describe tablename;
 Change:  alter table dist add column (url char(100));
Add auto-increment alter table ids modify column id int(11) auto_increment primary key;

Query

Basic query select * from tablename;
Highest value from int type column SELECT MAX(id) as id from contacts
 

SELECT id,user,username,pwdchgdat,email
    FROM cust
     WHERE menu != 'user'
     ORDER by username

Using DBI interface $sth1 = $dbh1->prepare("SELECT name1 from kna1 where kunnr = '00000$dc'");
$sth1->execute();
while (@row = $sth1->fetchrow_array()) {
$custname = $row[0];
}
$sth->finish();
Cool way to update when converting a file my $sth=$dbh->prepare('INSERT INTO cust (custno,user,pass,username,yorn1,pwdchgdat,yorn2,yorn3) VALUES (?,?,?,?,?,?,?,?)');
$sth->execute(@arr);
}


More MySQL





[Our portfolio] [A history of Computers and Networks]
[Perl help] [ABAP help] [MySQL help]
[TCP/IP troubleshooting] [HTML help] [Feedback] [Humor]
Advertise on Golden Ink's Georgia Network


In Association with Amazon.com