database

MySQL Queries

-- select 10 random row from table
SELECT column FROM TABLE
ORDER BY rand()
limit 10
 
-- update table (use join)
UPDATE table1
JOIN table2
ON table1.product = table2.a
SET table1.sku = table2.b
--where table1.product = 2138
 
-- view all databases
show databases;
 
-- view tables from database
show tables FROM mysql;
 
-- timestamp 7 days ago
date_sub(curdate(), INTERVAL 7 DAY);
 
-- format date
SELECT TO_CHAR(TIME, 'YYYY-MM-DD HH24:MI') FROM LOG;
 
-- replace first char to upercase
UPDATE customer SET first_name = CONCAT(UPPER(LEFT(first_name, 1)), SUBSTRING(first_name, 2)

Databases

DB Clients
http://www.squirrelsql.org - SQuirreL SQL, universal SQL Client, supports MS SQL and other DB

Connect from OpenOffice / LibreOffice to MsSQL Server
http://www.oooforum.org/forum/viewtopic.phtml?t=24036

Export MySQL Database

Login
mysql -u root -p

Links
phpMyAdmin - phpMyAdmin downloads

GUI
apt-get install -y mysql-admin

Allow access from outsice
sed -i 's|bind-address|#bind-address|g' /etc/mysql/my.cnf
/etc/init.d/mysql restart

Allow access to database magento for user dbo_magento from any host
GRANT ALL PRIVILEGES ON magento.* TO dbo_magento@'%' IDENTIFIED BY 'your_pass'

Links

Syndicate content