$ mysql -u root -p
CREATE DATABASE mydatabase CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> use mail;
Database changed
mysql> insert into users (login, name, password, maildir)
-> values ('info@domain.com', 'Robin Hood', ENCRYPT('arrow'), 'domain.com/boss/');
update users set name="Rob Roy" where login="info@domain.com";
select * from users where login="suspicious@domain.com";
delete from users where login="guisbern@domain.com";
update users set password=ENCRYPT("sword") where login="robin@sher.wood";
- how many Norman soldiers killed this week
mysql> SELECT SUM(killed_soldiers) FROM sherwood;
mysql> SELECT name, SUM(killed_soldiers) FROM sherwood GROUP BY name;
mysql>SELECT COUNT(*) FROM sherwood;
mysql>SELECT COUNT(*) FROM sherwood WHERE name="brtuck";
mysql> CREATE TABLE view;
mysql> use view;
mysql> CREATE TABLE user
> ( id SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
> login VARCHAR(30), name VARCHAR(40), num VARCHAR(7),
> active tinyint(1) );
mysql> insert into user (login,name,num ,active)
> values("brtuck","Brother Tuck","3255","1");
mysql> CREATE TABLE date
> ( id SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, datum DATE );
mysql> insert into date (datum) values ("1126-10-30");
mysql> CREATE TABLE main
> ( user SMALLINT NOT NULL PRIMARY KEY, date MEDIUMINT(6),
> val-A INT, in BIGINT, val-B INT, out BIGINT );
mysql> insert into main (user,date,val-A,in,val-B,out)
> values("1","2","17","8281723","39","7373171891901723");
mysql> show tables;
+-------------------+
| Tables_in_view |
+-------------------+
| date |
| main |
| user |
+-------------------+
3 rows in set (0.00 sec)
mysql> select * from date;
+----+------------+
| id | datum |
+----+------------+
| 2 | 1126-10-30 |
+----+------------+
1 row in set (0.00 sec)
mysql> select * from main;
+------+------+-------+---------+-------+------------------+
| user | date | val-A | in | val-B | out |
+------+------+-------+---------+-------+------------------+
| 1 | 2 | 17 | 8281723 | 39 | 7373171891901723 |
+------+------+-------+---------+-------+------------------+
1 row in set (0.00 sec)
mysql> select * from user;
+----+----------+--------------+-------+---------+
| id | login | name | num | active |
+----+----------+--------------+-------+---------+
| 1 | brtuck | Brother Tuck | 3255 | 1 |
+----+----------+--------------+-------+---------+
1 row in set (0.00 sec)
mysql> select user.name, date.datum, main.in, main.out from user, date, main
-> where main.user = user.id and main.date = date.id order by user.name;
+--------------+------------+---------+------------------+
| name | datum | in | out |
+--------------+------------+---------+------------------+
| Brother Tuck | 1126-10-30 | 8281723 | 7373171891901723 |
+--------------+------------+---------+------------------+
1 row in set (0.00 sec)
$ awk ' BEGIN{q="'\''"} {print "INSERT INTO users (login,name,num,active) VALUES(" q $1 q "," q $2 q "," q $3 q "," q "1" q ");"}'< space_delitmited_data.csv |mysql --host=localhost --user=username --password=yourpassword tablename
mysql> ALTER TABLE user AUTO_INCREMENT = 1;
mysql> ALTER TABLE tmp CHANGE user user varchar(30);
$ cat myfile
mysql --host=localhost --user=robin --password=marianne sherwood << EOF
SELECT name, killed_soldiers FROM robbers ORDER BY login LIMIT 2;
EOF
or
echo "SELECT name, killed_soldiers FROM robbers ORDER BY login LIMIT 2;" | mysql --host=localhost --user=robin --password=marianne sherwood
UPDATE main SET killed_normans = killed_normans + 300, silver_stolen = silver_stolen + 400 WHERE user=(SELECT id FROM user WHERE login='littlejohn') AND date=(SELECT id FROM date WHERE datum='1126-11-01');
insert into main (user, date, killed_normans, gold_stolen, silver_stolen, saved_vilagers) values ((SELECT id FROM user WHERE login='littlejohn'), (SELECT id FROM date WHERE datum='1126-11-01'), '11', '22', '10', '150');
alter table main add column id int(18) AUTO_INCREMENT PRIMARY KEY;
alter table main change column user user smallint(6) NOT NULL, DROP PRIMARY KEY;
mysqldump -u root -p --all-databases > alldb.sql
mysqldump -u root -p --opt --all-databases > alldb.sql
mysqldump -u root -p --all-databases --skip-lock-tables > alldb.sql
mysqldump -u root -p --skip-set-charset --default-character-set=binary sherwood>shwd.sql
mysql> alter table user add constraint FK_user2comp foreign key (comp_id) references comp(id);
mysql> alter table user drop foreign key FK_user2comp;
mysql> SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = 'tasklist' AND REFERENCED_TABLE_NAME = 'comp'; +------------+-------------+-----------------+-----------------------+------------------------+ | TABLE_NAME | COLUMN_NAME | CONSTRAINT_NAME | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME | +------------+-------------+-----------------+-----------------------+------------------------+ | task | comp_id | FK_task2comp | comp | id | | task | comp_id | FK_taskcomp | comp | id | | user | comp_id | FK_user2comp | comp | id | | user | firma_id | FK_user2firma | comp | id | +------------+-------------+-----------------+-----------------------+------------------------+ 4 rows in set (0.05 sec)
- HOME
~~~~~~~~~~~~~~~
- OpenBSD
- NetBSD
- FreeBSD
- Linux
- Solaris
- Windows
~~~~~~~~~~~~~~~
- Git
- Ansible
- Atlassian
- Network tools
- Qemu
- Virtualbox
- Vim
- Tmux
- Mutt
- STar
~~~~~~~~~~~~~~~
- MySQL
- PostgreSQL
- Postfix
- OpenSSL
- tcpdump
- SSH
~~~~~~~~~~~~~~~
- Packet Filter
- IP Filter
~~~~~~~~~~~~~~~
- Bash
- web-dev
- Hacking
- LINUX DAYS