15
BioinfRes SoSe 16 Bioinforma)cs Resources - SQL - Lecture & Exercises Prof. B. Rost, Dr. L. Richter, J. Reeb Ins)tut für Informa)k I12

Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

Bioinforma)csResources-SQL-

Lecture&ExercisesProf.B.Rost,Dr.L.Richter,J.Reeb

Ins)tutfürInforma)kI12

Page 2: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

SQLinuse●  SyntaxofMySQLserver5.6●  usefulu)li)es:mysql,mysqladmin

●  frequenttasks/opera)ons

●  commandline●  Pythonintegra)on

Page 3: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

Prerequisites

●  Knowyourserverversion:EvenifSQLisastandard,differentvendorsimplementdifferentversionsofaddvendor/versionspecificfeatures

●  Haveclientprogramsinstalled(mysql,mysqladmin)

●  Havealanguagedriver/connectorinstalled

Page 4: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

Prerequisites

●  commandlineclientscometypicallywiththeinstalla)on

●  GUIclientsarealsoavailable●  Connectorscomeindifferentflavorsformanylanguagesandmayhavetobeinstalled

●  ConnectorsmayofferdifferentAPIs

Page 5: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

(User)Administra)on

●  Administra)oninforma)onisstoredinthedatabase‘mysql’

●  Usershavetoconnecttothedatabaseserver●  Usersaremanagedviaaccounts:-  username-  hostname/IPaddress-  op)onalpassword

Page 6: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

(User)Administra)on

●  Example:‘dowj’@’myhost’●  specialhostnames:localhost,127.0.0.1,::1

●  ‘empty’username:anonymous

●  hostnamesmaycontainwildcards:%or_●  omissionofuserorhostnameallowed

●  passwordcanbeandissetindividuallyforeachname/hostcombina)on

Page 7: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

Example

●  Set/changepassword:SETPASSWORDfor‘dowj’@’localhost’=PASSWORD(‘cleartext_password’)

+---------+-------------------+----------+!| user | host | password |!+---------+-------------------+----------+!| root | localhost | *CABC7 |!| root | phoenix.fritz.box | *CABC7 |!| root | 127.0.0.1 | *CABC7 |!| root | ::1 | *CABC7 |!| | localhost | |!| | phoenix.fritz.box | |!| richter | localhost | *75B62 |!+---------+-------------------+----------+!

Page 8: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

MoreAdministra)on

●  default:onlyrootaccount,mightbeunsecured●  databases:mysql,informa)on_schema,performanceschema,test

●  furthercrea)onofuseraccountanddatabasesneeded

Page 9: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

MoreAdministra)on

●  usethemysqladmintooltocreateanew,emptydatabase:mysqladmin -u root -p create resource_db!

●  createauser(inamysqlsession):CREATE USER dowj [identified by ‘clear_pw’]

●  nowyouhavetograntprivilegesonacertaindatabasetotheuser:GRANT ALL ON resource_db.* TO ‘dowj’@’localhost’

Page 10: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

FullGrantSyntax1GRANT!

priv_type [(column_list)]!

[, priv_type [(column_list)]] ...!

ON [object_type] priv_level!

TO user_specification [, user_specification] ...!

[REQUIRE {NONE | tsl_option [[AND] tsl_option] ...}]!

[WITH {GRANT OPTION | resource_option} ...]!

GRANT PROXY ON user_specification!

TO user_specification [, user_specification] ...!

[WITH GRANT OPTION]!

object_type: {!

TABLE!

| FUNCTION!

| PROCEDURE!

}!

Page 11: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

FullGrantSyntax2priv_level: {!

*!

| *.*!

| db_name.*!

| db_name.tbl_name!

| tbl_name!

| db_name.routine_name!

}!

user_specification:!

user [ auth_option ]!

auth_option: {!

IDENTIFIED BY 'auth_string'!

| IDENTIFIED BY PASSWORD 'hash_string'!

| IDENTIFIED WITH auth_plugin!

| IDENTIFIED WITH auth_plugin AS 'hash_string'!

}!

!

Page 12: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

FullGrantSyntax3tsl_option: {!

SSL!

| X509!

| CIPHER 'cipher'!

| ISSUER 'issuer'!

| SUBJECT 'subject'!

}!

!

resource_option: {!

| MAX_QUERIES_PER_HOUR count!

| MAX_UPDATES_PER_HOUR count!

| MAX_CONNECTIONS_PER_HOUR count!

| MAX_USER_CONNECTIONS count!

}!

Page 13: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

Privileges

from http://dev.mysql.com/doc/refman/5.6/en/grant.html

Page 14: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

DataExport/Import●  hjp://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

●  mysqldumptocreatelogicalbackupsi.e.●  asetofSQLstatementstoreproducethecurrentstateofthedatabase

●  otheroutputformatsthanSQL:CSV,XML●  requiretherespec)veprivileges

●  Examples:mysqldump [options] db_name [tbl_name ...] mysqldump [options] --databases db_name ... mysqldump [options] --all-databases!

Page 15: Bioinformacs Resources - SQL - Rostlab · BioinfRes SoSe 16 Prerequisites Know your server version: Even if SQL is a standard, different vendors implement different versions of

BioinfRes SoSe 16

DataExport/Import●  easybackupoflogicaldumps:●  inthemysqlclient:source file_name!

●  otherwise:createemptytablesanduseLOADDATAINFILE-  canbequitetrickybecauseofinputformatspecifica)on