SlideShare a Scribd company logo
Managing	
  a	
  shared	
  MySQL	
  farm
 Thijs	
  Feryn
 Evangelist
 +32	
  (0)9	
  218	
  79	
  06
 thijs@combellgroup.com

 Dutch	
  PHP	
  Conference
 Saturday	
  May	
  21st	
  2011
 Amsterdam,	
  The	
  Netherlands
About	
  me




 I’m	
  an	
  evangelist	
  at	
  Combell
About	
  me




 I’m	
  a	
  board	
  member	
  at	
  PHPBenelux
I	
  live	
  in	
  the	
  wonderful	
  city	
  of	
  Bruges
      MPBecker	
  -­‐	
  Bruges	
  by	
  Night	
  hXp://www.flickr.com/photos/galverson2/3715965933
Follow	
  me	
  on	
  TwiXer:	
  @ThijsFeryn

Give	
  me	
  feedback:	
  hXp://joind.in/3247

  Read	
  my	
  blog:	
  hXp://blog.feryn.eu
Managing a shared mysql farm dpc11
Managing a shared MySQL farm
             tekst
Provisioning/authentication/
permissions

Managing a shared MySQL farm
              tekst
Several clients/apps
       connect to it

Managing a shared MySQL farm
             tekst
Multiple servers

Managing a shared MySQL farm
             tekst
The	
  farm
Managing	
  the	
  farm
Managing	
  the	
  farm


                            User



                      Permissions



                          Database
Managing	
  users



    ✓Create	
  user
    ✓Remove	
  user
    ✓Enable/disable	
  user
    ✓Reset	
  password
Managing	
  databases



   ✓Create	
  database
   ✓Remove	
  database
   ✓Enable/disable	
  database
   ✓Set	
  quota
Managing	
  permissions



   ✓Grant	
  permissions
   ✓Revoke	
  permissions
   ✓Enable	
  wricng
   ✓Disable	
  wricng
MySQL	
  authenccacon	
  &	
  privileges
MySQL	
  privilege	
  system

               Global	
  privileges

             Database	
  privileges

               Table	
  privileges

                Field	
  privileges
MySQL	
  privilege	
  system

  Global	
  privileges         mysql.user

Database	
  privileges         mysql.db

  Table	
  privileges          mysql.tables_priv

   Field	
  privileges         mysql.columns_priv
General	
  privileges

✓Select             ✓Alter
✓Insert             ✓Create	
  tmp	
  table
✓Update             ✓Lock	
  tables
✓Delete             ✓Create	
  view
✓Create             ✓Show	
  view
✓Drop               ✓Create	
  roucne
✓Grant              ✓Alter	
  roucne
✓References         ✓Execute	
  priv
✓Index
Server	
  privileges

✓Reload                ✓Max	
  quescons
✓Shutdown              ✓Max	
  updates
✓Process               ✓Max	
  conneccons
✓File                  ✓Max	
  user	
  conneccons
✓Show_db
✓Super
Which	
  privileges	
  to	
  grant?
Which	
  privileges	
  to	
  grant?

✓Select             ✓Alter
✓Insert             ✓Create	
  tmp	
  table
✓Update             ✓Lock	
  tables
                                          ✓Reload
✓Delete             ✓Create	
  view
                                          ✓Shutdown
✓Create             ✓Show	
  view
                                          ✓Process
✓Drop               ✓Create	
  roucne File
                                          ✓
✓Grant              ✓Alter	
  roucne
                                          ✓Show_db
✓References         ✓Execute	
  priv
                                          ✓Super
✓Index
Manage	
  privileges

✓CREATE	
  USER
✓DROP	
  USER
✓GRANT
✓RENAME	
  USER
✓REVOKE
✓SET	
  PASSWORD
Manage	
  privileges


✓Manually	
  in	
  mysql.user
✓Manually	
  in	
  mysql.db
✓Manually	
  in	
  mysql.tables_priv
✓Manually	
  in	
  mysql.columns_priv
Challenges
Challenges



  ✓Management	
  across	
  mulcple	
  nodes
  ✓Aggregacng	
  data	
  from	
  mulcple	
  nodes
  ✓Name	
  clashes
  ✓Quota	
  management
Solucons
Solucons


 ✓Centralized	
  provisioning	
  database
 ✓GeXers	
  on	
  the	
  provisioning	
  database
 ✓Node	
  mapper	
  for	
  user/db/privilege	
  
 management
 ✓INFORMATION_SCHEMA	
  for	
  quota	
  
 management
 ✓Prefixes	
  to	
  avoid	
  name	
  clashes
Provisioning	
  plan
User         Database
✓Id           ✓Id
✓Prefix        ✓Node
✓Username     ✓Prefix
✓Password     ✓Database
✓Enabled      ✓Quota
✓DatabaseId   ✓Enabled
✓Write        ✓Down
✓CreateDate   ✓Overquota
✓UpdateDate   ✓CreateDate
              ✓UpdateDate
User         Database
✓Id           ✓Id          Mulcple
✓Prefix        ✓Node         servers
✓Username     ✓Prefix
                          Database	
  
✓Password     ✓Database    on	
  single	
  
✓Enabled      ✓Quota         node
✓DatabaseId   ✓Enabled
✓Write        ✓Down
✓CreateDate   ✓Overquota
✓UpdateDate   ✓CreateDate
              ✓UpdateDate
Managing a shared mysql farm dpc11
Mapping	
  uses	
  cases	
  to	
  SQL
✓Add	
  user
✓Delete	
  user
✓Reset	
  user	
  password
✓Enable	
  user
✓Disable	
  user
✓Get	
  user
Add	
  user


INSERT INTO `user`
(`prefix`,`username`,`password`,`createdate`)
VALUES(‘test’,‘test_user’,‘mypass123’,NOW());
Delete	
  user


DELETE FROM `user`
WHERE username=‘test_user’;

DELETE u.*, db.* FROM `mysql`.`user` u
LEFT JOIN `mysql`.`db` db
ON(db.`User` = u.`User`)
WHERE u.`User` = ‘test_user’;
Reset	
  user	
  password


UPDATE `user`
SET `password` = ‘newpass123’
WHERE `username` = ‘test_user’;

UPDATE `mysql`.`user`
SET `Password` = PASSWORD
(‘newpass123’)
WHERE `User`= ‘test_user’;
Enable	
  user


UPDATE `user`
SET `enabled` = '1'
WHERE `username` = ‘test_user’;

UPDATE `mysql`.`user`
SET `Host` = ‘%’
WHERE `User`= ‘test_user’
Disable	
  user


UPDATE `user`
SET `enabled` = '0'
WHERE `username` = ‘test_user’;

UPDATE `mysql`.`user`
SET `Host` = ‘localhost’
WHERE `User`= ‘test_user’
Get	
  user




SELECT * FROM `user`
WHERE `username` = ‘test_user’;
✓Add	
  database
✓Delete	
  database
✓Set	
  database	
  quota
✓Enable	
  database
✓Disable	
  database
✓Get	
  database
Add	
  database

INSERT INTO `database`
(`node`,`prefix`,`database`,`quota`,`c
reatedate`) VALUES(1,‘test’,‘test_db’,
10,NOW());


CREATE DATABASE test_db1;
Delete	
  database




DELETE FROM `database`
WHERE `database` = ‘test_db’;
Delete	
  database
                                          Are	
  
                                     linked	
  to	
  this	
  
                                       database
SELECT u.username
FROM `user` u
WHERE u.databaseId = 123
GROUP BY u.username;                  Find	
  
                           deletable	
  users	
  to	
  
                           delete	
  from	
  MySQL	
  	
  
                            privileges	
  system
Delete	
  database

DELETE u.*, db.*
FROM `user` u
LEFT JOIN `db` db
ON(db.`User` = u.`User`)
WHERE u.`User` IN('test_user’);
                          Delete
                     these	
  users	
  from	
  
                     MySQL	
  	
  privileges	
  
                         system
Delete	
  database



DROP DATABASE test_db;
Set	
  database	
  quota




UPDATE `database`
SET `quota` = 100
WHERE `database` = ‘test_db’;
Enable	
  database


UPDATE `database` SET
`enabled` = '1'
WHERE `database` = ‘test_db’;
Enable	
  database




SELECT u.username, u.write
FROM user u
WHERE u.databaseId = 123
                                     Find	
  
                             user	
  mappings	
  
                              to	
  re-­‐enable
Enable	
  database

INSERT INTO `db`
(Host,Db,User,Select_priv,Insert_priv,
Update_priv,Delete_priv,Create_priv,Drop_pr
iv,Grant_priv,References_priv,
Index_priv,Alter_priv,Create_tmp_table_priv
,Lock_tables_priv,
Create_view_priv,Show_view_priv,Create_rout
ine_priv,
Alter_routine_priv,Execute_priv)
Write	
  
Enable	
  database                  permissions

VALUES
(‘%’,‘test_db’,‘test_user’,'Y','Y','Y','Y',
'Y','Y','N','Y','Y','Y'
,'Y','Y','Y','Y','Y','Y','Y');       Read-­‐
                                      only	
  
                                  permissions
VALUES
(‘%’,‘test_db’,‘test_user’,'Y','N','N','N',
'N','N','N','N','N','N','N','N','N','Y','N'
,'N','Y');
Disable	
  database


UPDATE `database` SET
`enabled` = '0'
WHERE `database` = ‘test_db’;

DELETE FROM `db`
WHERE db = 'test_db’;
Get	
  database




SELECT * FROM `database`
WHERE `database` = ‘test_db’;
✓Grant	
  privilege
✓Revoke	
  privilege
✓Enable	
  database	
  wricng
✓Disable	
  database	
  wricng
Write	
  
Grant	
  privilege            permissions

UPDATE `user`
SET `databaseId`=123, `write`='1'
WHERE `username`= ‘test_user’;
                                 Read-­‐
                                  only	
  
                              permissions
UPDATE `user`
SET `databaseId`=123, `write`='0'
WHERE `username`= ‘test_user’;
Grant	
  privilege
                                    Try	
  
                           adding	
  user	
  or	
  
                           catch	
  duplicate	
  
                            user	
  error

INSERT INTO `user`(Host,User,Password)
VALUES(‘%’,‘test_user’,PASSWORD
(‘password’));
Grant	
  privilege

INSERT INTO `db`
(Host,Db,User,Select_priv,Insert_priv,
Update_priv,Delete_priv,Create_priv,Drop_pr
iv,Grant_priv,References_priv,
Index_priv,Alter_priv,Create_tmp_table_priv
,Lock_tables_priv,
Create_view_priv,Show_view_priv,Create_rout
ine_priv,
Alter_routine_priv,Execute_priv)
Write	
  
Grant	
  privilege                  permissions

VALUES
(‘%’,‘test_db’,‘test_user’,'Y','Y','Y','Y',
'Y','Y','N','Y','Y','Y'
,'Y','Y','Y','Y','Y','Y','Y');       Read-­‐
                                      only	
  
                                  permissions
VALUES
(‘%’,‘test_db’,‘test_user’,'Y','N','N','N',
'N','N','N','N','N','N','N','N','N','Y','N'
,'N','Y');
Revoke	
  privilege


UPDATE `user`
SET `databaseId`= NULL, `write`= NULL
WHERE `user`= ‘test_user’;

DELETE u.*, db.* FROM `user` u LEFT JOIN
`db` db ON(db.`User` = u.`User`) WHERE
u.`User` = ‘test_user’;
Enable	
  database	
  wricng




UPDATE `user` SET `write`= '1'
WHERE `username` = ‘test_user’;
Enable	
  database	
  wricng
UPDATE `db` SET
`Select_priv` = 'Y',`Insert_priv` = 'Y',
UPDATE `user`'Y',`Delete_priv` '1'
`Update_priv` =
                 SET `write`= = 'Y',
WHERE `username` = ‘test_user’;
`Create_priv` = 'Y',`Drop_priv` = 'Y',
`Grant_priv` = 'N',`References_priv` = 'Y',
`Index_priv` = 'Y',`Alter_priv` = 'Y',
`Create_tmp_table_priv`='Y',`Lock_tables_priv` =
'Y',
`Create_view_priv` = 'Y',`Show_view_priv` =
'Y',`Create_routine_priv` = 'Y',
`Alter_routine_priv` = 'Y',`Execute_priv` = 'Y'
WHERE `db`= ‘test_db’ AND `user` = ‘test_user’;
Disable	
  database	
  wricng




UPDATE `user` SET `write`= '0'
WHERE `username` = ‘test_user’;
Disable	
  database	
  wricng
UPDATE `db` SET
`Select_priv` = 'Y',`Insert_priv` = 'N',
UPDATE `user`'N',`Delete_priv` '1'
`Update_priv` =
                 SET `write`= = 'N',
WHERE `username` = ‘test_user’;
`Create_priv` = 'N',`Drop_priv` = 'N',
`Grant_priv` = 'N',`References_priv` = 'N',
`Index_priv` = 'N',`Alter_priv` = 'N',
`Create_tmp_table_priv`='N',`Lock_tables_priv` =
'N',
`Create_view_priv` = 'N',`Show_view_priv` =
'Y',`Create_routine_priv` = 'N',
`Alter_routine_priv` = 'N',`Execute_priv` = 'Y'
WHERE `db`= ‘test_db’ AND `user` = ‘test_user’;
Quota	
  management
Quota	
  management


✓Limits	
  in	
  provisioning	
  database
✓Current	
  usage	
  stored	
  in	
  
INFORMATION_SCHEMA
✓Raco	
  calculated	
  via	
  cron	
  task
✓Write	
  permissions	
  disabled	
  while	
  over	
  quota
Quota	
  management

SELECT `database`,`quota`
FROM `database`

SELECT TABLE_SCHEMA as `database`,
ROUND(SUM(DATA_LENGTH + INDEX_LENGTH)/
1048576,2) as `usage`
FROM `information_schema`.`TABLES`
GROUP BY TABLE_SCHEMA
Quota	
  management



UPDATE `database`
SET `overquota` = '1'
WHERE `database` = ‘test_db’;
Quota	
  management
UPDATE `db` SET
`Select_priv` = 'Y',`Insert_priv` = 'N',
`Update_priv` = 'N',`Delete_priv` = 'Y',
`Create_priv` = 'N',`Drop_priv` = 'Y',
`Grant_priv` = 'N',`References_priv` = 'N',
`Index_priv` = 'N',`Alter_priv` = 'N',
`Create_tmp_table_priv` =
'N',`Lock_tables_priv` = 'N',
`Create_view_priv` = 'N',`Show_view_priv` =
'Y',`Create_routine_priv` = 'N',
`Alter_routine_priv` = 'N',`Execute_priv` =
'Y' WHERE `db`= ‘test_database’
Quota	
  management



UPDATE `database`
SET `overquota` = '0'
WHERE `database` = ‘test_db’;
Quota	
  management
UPDATE `db` SET
`Select_priv` = 'Y',`Insert_priv` = 'Y',
`Update_priv` = 'Y',`Delete_priv` = 'Y',
`Create_priv` = 'Y',`Drop_priv` = 'Y',
`Grant_priv` = 'N',`References_priv` = 'Y',
`Index_priv` = 'Y',`Alter_priv` = 'Y',
`Create_tmp_table_priv`=
'Y',`Lock_tables_priv` = 'Y',
`Create_view_priv` = 'Y',`Show_view_priv` =
'Y',`Create_routine_priv` = 'Y',
`Alter_routine_priv` = 'Y',`Execute_priv` =
'Y' WHERE `db`= ‘test_db’
Goals
Single	
  point	
  of	
  management
Single	
  point	
  of	
  conneccon
Replicacon	
  &	
  loadbalancing
Replicacon	
  &	
  loadbalancing


✓Minimizes	
  risk
✓Ensures	
  stability,	
  scalability	
  &	
  performance
✓Copies	
  databases	
  across	
  nodes
✓Doesn’t	
  parccon/shard	
  databases
✓Will	
  require	
  mulcple	
  independent	
  clusters
Proxying	
  strategies
Server	
  proxy
Server	
  proxy


MySQL	
  Proxy	
  is	
  a	
  simple	
  program	
  that	
  
sits	
  between	
  your	
  client	
  and	
  MySQL	
  
server(s)	
  that	
  can	
  monitor,	
  analyze	
  or	
  
transform	
  their	
  communicacon.
MySQL	
  Proxy	
  features



✓	
  Load	
  balancing
✓	
  Failover
✓	
  Query	
  analysis
✓	
  Query	
  filtering	
  and	
  modificacon
Installacon


              APT-­‐GET	
  INSTALL
✓mysql-­‐proxy
✓lua5.1
✓liblua5.1-­‐0-­‐dev
✓liblua5.1-­‐sql-­‐mysql-­‐2
✓liblua5.1-­‐memcached0
✓liblua5.1-­‐md5-­‐0
Startup
/usr/bin/mysql-­‐proxy	
  
-­‐-­‐proxy-­‐lua-­‐script=/var/www/mysqlproxy.dev/	
  
proxy.lua	
  -­‐-­‐proxy-­‐address=:3307	
  	
  
-­‐-­‐proxy-­‐backend-­‐addresses=172.16.26.133:3306	
  
-­‐-­‐proxy-­‐backend-­‐addresses=172.16.26.134:3306	
  
-­‐-­‐lua-­‐path=/usr/share/lua/5.1/?.lua	
  
-­‐-­‐lua-­‐cpath=/usr/lib/lua/5.1/?.so
                                               Custom	
  
                                              LUA	
  library


           /etc/default/mysql-­‐proxy
Hooks

✓connect_server
✓read_handshake
✓read_auth
✓read_auth_result
✓read_query
✓read_query_result
✓disconnect_client
Goal
Goal


✓	
  Accept	
  conneccon	
  using	
  the	
  proxy
✓Hook	
  into	
  the	
  authenccacon
✓Match	
  user	
  to	
  the	
  provisioning	
  DB
✓Fetch	
  node	
  from	
  provisioning
✓Switch	
  to	
  the	
  right	
  node
➡Effeccve	
  proxying	
  solucon
Reality
Reality


✓	
  Accept	
  conneccon	
  using	
  the	
  proxy
✓Hook	
  into	
  the	
  authenccacon
✓Match	
  user	
  to	
  the	
  provisioning	
  DB
✓Fetch	
  node	
  from	
  provisioning
✓Switch	
  to	
  the	
  right	
  node
➡Effeccve	
  proxying	
  solucon
Reality

Conneccon	
  switching	
  only	
  happens	
  in	
  the	
  
        connect_server	
  hook




  Auth	
  info	
  is	
  only	
  available	
  starcng	
  from	
  
                 the	
  read_auth	
  hook
Bridge	
  the	
  gap
Bridge	
  the	
  gap




     Redirect	
  to	
  node	
  based	
  on	
  client	
  IP
Let’s	
  see	
  some	
  code	
  !
Code
require('luarocks.require')
require('md5')
require('Memcached')
require('luasql.mysql')
local	
  memcache	
  =	
  Memcached.Connect()
-­‐-­‐-­‐	
  config
local	
  mysqlhost	
  =	
  "localhost"
local	
  mysqluser	
  =	
  "myUser"
local	
  mysqlpassword	
  =	
  "MyPwDsesd"
local	
  mysqldatabase	
  =	
  "test"
-­‐-­‐	
  debug
local	
  debug	
  =	
  true


                Dependencies	
  &	
  config
Code
function	
  error_result	
  (msg)
	
   proxy.response	
  =	
  {
	
   	
       type	
  =	
  proxy.MYSQLD_PACKET_ERR,
	
   	
       errmsg	
  =	
  msg,
	
   	
       errcode	
  =	
  7777,
	
   	
       sqlstate	
  =	
  'X7777',
	
   }
	
   return	
  proxy.PROXY_SEND_RESULT
end


                Custom	
  MySQL	
  errors
function	
  node_get(ip)
	
     local	
  node	
  =	
  memcache:get(md5.sumhexa(ip))
Code
	
  
	
     if	
  not	
  node	
  ==	
  nil	
  then
	
     	
  	
  	
  return	
  loadstring('return	
  '..memcache:get(md5.sumhexa
(ip)))()	
                	
  
	
     end
	
  
	
     node	
  =	
  sql_get(ip)
	
     if	
  node	
  ==	
  nil	
  then
	
     	
  	
  	
  	
  return	
  nil
	
     end

      	
  	
  	
  memcache:set(md5.sumhexa(ip),	
  node,	
  3600)	
  
      	
  	
  	
  return	
  node
end



           Get	
  node	
  from	
  cache	
  or	
  database
function	
  sql_get(ip)	
  
	
       env	
  =	
  assert	
  (luasql.mysql())
Code
	
       con	
  =	
  assert	
  (env:connect
(mysqldatabase,mysqluser,mysqlpassword,mysqlhost))
	
       cur	
  =	
  assert	
  (con:execute(string.format("SELECT	
  
n.`id`	
  FROM	
  `accesslist`	
  a	
  JOIN	
  `node`	
  n	
  ON(n.id=a.node)	
  
WHERE	
  a.`ip`	
  =	
  '%s'",ip)))	
  
	
       row	
  =	
  cur:fetch	
  ({},	
  "a")
	
       if	
  cur:numrows()	
  ==	
  0	
  then
	
       	
          return	
  nil
	
       end
	
       cur:close()
	
       con:close()
	
       env:close()
	
       return	
  row.id
end


      Get	
  node	
  from	
  provisioning	
  database
Code
function	
  connect_server()
	
  	
  	
  	
  selectedNode	
  =	
  node_get
(proxy.connection.client.src.address)

	
  	
  	
  	
  if	
  selectedNode	
  ==	
  nil	
  then
	
  	
  	
  	
  	
  	
  	
  	
  return	
  error_result(string.format("No	
  info	
  found	
  in	
  
the	
  cluster	
  for	
  IP	
  
'%s'",proxy.connection.client.src.address))
	
  	
  	
  	
  end

	
  	
  	
  	
  proxy.connection.backend_ndx	
  =	
  selectedNode	
   	
  
end


                 Retrieve	
  and	
  switch	
  to	
  node
Reality



  MySQL	
  Proxy	
  is	
  not	
  accvely	
  supported
Client	
  proxy
MySQL	
  Nacve	
  Driver
MySQL	
  Nacve	
  Driver


✓Replacement	
  for	
  libmysql
✓Full	
  client	
  protocol	
  as	
  a	
  PHP	
  extension
✓Official	
  since	
  PHP	
  5.3.0
✓No	
  API
✓Mysql,	
  Mysqli	
  &	
  PDO	
  use	
  it
✓Supports	
  plugins
MySQL	
  Nacve	
  Driver                    Read	
  
                                      these	
  blog	
  posts



             hXp://blog.ulf-­‐wendel.de/?p=284

 hXp://schlueters.de/blog/archives/146-­‐mysqlnd-­‐plugins-­‐
                for-­‐PHP-­‐in-­‐praccce.html
MySQL	
  Nacve	
  Driver

✓	
  Accept	
  conneccon	
  using	
  the	
  proxy
✓Hook	
  into	
  the	
  authenccacon
✓Match	
  user	
  to	
  the	
  provisioning	
  DB
✓Fetch	
  node	
  from	
  provisioning
✓Switch	
  to	
  the	
  right	
  node
✓Doesn’t	
  work	
  for	
  remote	
  conneccons
➡Effeccve	
  proxying	
  solucon
DNS	
  &	
  hostnames




             Hostname	
  per	
  account
What	
  about	
  PhpMyAdmin?
What	
  about	
  PhpMyAdmin?


✓Use	
  single	
  signon	
  auth	
  module
✓Use	
  customized	
  fallback	
  auth	
  module
✓Detect	
  linked	
  database	
  &	
  node
✓Switch	
  to	
  node
config.inc.php
<?php
$cfg['Servers'][1]['auth_type'] = 'httpsoap';
$cfg['Servers'][1]['host'] = '1.2.3.4';
$cfg['Servers'][1]['connect_type'] = 'tcp';
$cfg['Servers'][1]['compress'] = false;
$cfg['Servers'][1]['extension'] = 'mysql';
$cfg['Servers'][1]['AllowNoPassword'] = false;
$cfg['Servers'][2]['auth_type'] = 'httpsoap';
$cfg['Servers'][2]['host'] = '1.2.3.4';
$cfg['Servers'][2]['connect_type'] = 'tcp';
$cfg['Servers'][2]['compress'] = false;
$cfg['Servers'][2]['extension'] = 'mysql';
$cfg['Servers'][2]['AllowNoPassword'] = false;
$cfg['Servers'][3]['extension'] = 'mysql';
$cfg['Servers'][3]['auth_type'] = 'signon';
$cfg['Servers'][3]['SignonSession'] = 'SSOSession';
$cfg['Servers'][3]['SignonURL'] = 'scripts/signon.php';
$cfg['Servers'][3]['LogoutURL'] = 'scripts/signon-logout.php';
scripts/signon.php
<?php
if (isset($_REQUEST['user'])) {
    try{
        $soap = new SoapClient('http://my.soap-
webservice.net/?WSDL');
        $user = $soap->user_getByUsername($_REQUEST['user']);
        if(!isset($_REQUEST['hash'])){
           die("No hash submitted");
        }
        if(sha1($user->username.$user-
>password.'azertyuiop') !== $_REQUEST['hash']){
            die("Invalid hash");
        }
    } catch (Exception $e){
        die("No such user");
    }
...
scripts/signon.php
    session_set_cookie_params(0, '/', '', 0);
    $session_name = 'SSOSession';
    session_name($session_name);
    session_start();
    $_SESSION['PMA_single_signon_user'] = $user->username;
    $_SESSION['PMA_single_signon_password'] = $user-
>password;
    $_SESSION['PMA_single_signon_host'] = $user->node;
    $_SESSION['PMA_single_signon_port'] = '3306';
    $id = session_id();
    session_write_close();
    header('Location: ../index.php?server=3');
} else {
        exit();
    header('Location: ../index.php?server=1');
}
scripts/signon-­‐logout.php


<?php
session_set_cookie_params(0, '/', '', 0);
$session_name = 'SSOSession';
session_name($session_name);
session_start();
session_destroy();
header('Location: ../index.php?server=1');
Customized	
  fallback	
  auth	
  module


✓Copy	
  of	
  ./libraries/auth/h>p.auth.lib.php
✓Modify	
  PMA_auth_set_user()	
  funccon
✓Implement	
  deteccon	
  logic
✓Communicates	
  with	
  provisioning	
  service
✓Retrieves	
  database	
  &	
  node
✓Switches	
  to	
  node
libraries/auth/hXpsoap.auth.lib.php
<?php
function PMA_auth_set_user()
{
    global $cfg, $server;
    global $PHP_AUTH_USER, $PHP_AUTH_PW;
    try{
        $soap = new SoapClient('http://my.soap-
webservice.net/?WSDL');
        $user = $soap->user_getByUsername
($PHP_AUTH_USER);
        $cfg['Server']['host'] = $user->node;
    } catch (Exception $e){
        PMA_auth();
        return true;
    }
...
libraries/auth/hXpsoap.auth.lib.php
if ($cfg['Server']['user'] != $PHP_AUTH_USER) {
  $servers_cnt = count($cfg['Servers']);
  for ($i = 1; $i <= $servers_cnt; $i++) {
   if (isset($cfg['Servers'][$i])
    && ($cfg['Servers'][$i]['host'] == $cfg['Server']
['host'] && $cfg['Servers'][$i]
['user'] == $PHP_AUTH_USER)) {
     $server = $i;
                $cfg['Server'] = $cfg['Servers'][$i];
                break;
            }
        }
    }
    $cfg['Server']['user']     = $PHP_AUTH_USER;
    $cfg['Server']['password'] = $PHP_AUTH_PW;
    return true;
}
Managing a shared mysql farm dpc11
Q&A

More Related Content

PDF
Managing a shared_mysql_farm_phpday2011
PDF
Nagios Conference 2012 - Sheeri Cabral - Alerting With MySQL and Nagios
PDF
Cassandra Summit 2013 Keynote
PPTX
PDF
Cassandra summit keynote 2014
PDF
Tokyo cassandra conference 2014
PPTX
[PHP] Zend_Db (Zend Framework)
PDF
Top5 scalabilityissues
Managing a shared_mysql_farm_phpday2011
Nagios Conference 2012 - Sheeri Cabral - Alerting With MySQL and Nagios
Cassandra Summit 2013 Keynote
Cassandra summit keynote 2014
Tokyo cassandra conference 2014
[PHP] Zend_Db (Zend Framework)
Top5 scalabilityissues

What's hot (20)

PDF
Rails' Next Top Model
PDF
Cassandra Summit 2015
PDF
Cloud, Cache, and Configs
PPTX
Hazelcast
PDF
Dependency Injection with PHP and PHP 5.3
PPT
Knockout
PPTX
ATG Secure Repository
PPTX
DevOpsDays Warsaw 2015: Running High Performance And Fault Tolerant Elasticse...
PDF
Caching and Scaling WordPress using Fragment Caching
ODP
Modularized Persistence - B Zsoldos
PDF
MySQL Document Store
PDF
[2019] 200만 동접 게임을 위한 MySQL 샤딩
DOCX
SCasia 2018 MSFT hands on session for Azure Batch AI
PDF
Introduction to Data Modeling with Apache Cassandra
PPTX
Replication and Replica Sets
PPTX
Replication and Replica Sets
PDF
spring3.2 java config Servler3
PPTX
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
PPT
02 hibernateintroduction
PDF
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Rails' Next Top Model
Cassandra Summit 2015
Cloud, Cache, and Configs
Hazelcast
Dependency Injection with PHP and PHP 5.3
Knockout
ATG Secure Repository
DevOpsDays Warsaw 2015: Running High Performance And Fault Tolerant Elasticse...
Caching and Scaling WordPress using Fragment Caching
Modularized Persistence - B Zsoldos
MySQL Document Store
[2019] 200만 동접 게임을 위한 MySQL 샤딩
SCasia 2018 MSFT hands on session for Azure Batch AI
Introduction to Data Modeling with Apache Cassandra
Replication and Replica Sets
Replication and Replica Sets
spring3.2 java config Servler3
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
02 hibernateintroduction
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Ad

Viewers also liked (20)

PPSX
13 og english presentation 3-6-2010
PPS
Digital Agency Gaumina
PDF
CLI, the other SAPI
PPSX
Poesiamodernainglesa 090516190151 Phpapp02
PDF
Ecce - Mock Comments
PPT
Tree Swing
PDF
Gamify Your Work
PDF
Hop on for a quick tour of the streets of Australia
PPT
Towards an Agile Design Process
PPT
La Placa Base
PDF
Pangandaran 2007
PDF
Banish Your Inner Critic to Unleash Creativity – edUi Conference 2015
PDF
It's Business Time: The Graceful Degradation of CSS3
PDF
Maine Residence Presentation
PDF
Find Your (Shameless) Spark
PDF
Infinite Possibilities - Giant Conference 2015
PPT
Milieuproblematiek
PDF
Making Your Own URL Shortening Service
PDF
Review for the final exam, gilmar
PDF
Let’s Rawk The Web - A Manifesto
13 og english presentation 3-6-2010
Digital Agency Gaumina
CLI, the other SAPI
Poesiamodernainglesa 090516190151 Phpapp02
Ecce - Mock Comments
Tree Swing
Gamify Your Work
Hop on for a quick tour of the streets of Australia
Towards an Agile Design Process
La Placa Base
Pangandaran 2007
Banish Your Inner Critic to Unleash Creativity – edUi Conference 2015
It's Business Time: The Graceful Degradation of CSS3
Maine Residence Presentation
Find Your (Shameless) Spark
Infinite Possibilities - Giant Conference 2015
Milieuproblematiek
Making Your Own URL Shortening Service
Review for the final exam, gilmar
Let’s Rawk The Web - A Manifesto
Ad

Similar to Managing a shared mysql farm dpc11 (20)

PPTX
Locking Down Your MySQL Database.pptx
PDF
MySQL server security
PPT
My sql presentation
PDF
Mysql nowwhat
PPT
My sql with querys
PDF
Mysqldbatrainingsession12privilegesinmysql 170302152348
PDF
A Tour to MySQL Commands
PDF
Percona Live 2012PPT:mysql-security-privileges-and-user-management
PPTX
Vansh Goel ISM (1).pptx
PDF
MySQL for beginners
PPTX
MySQL DBA OCP 1Z0-883
PDF
Mysqlsecurityoptionsjan2021
PPT
ODP
Msql
PPT
Mysql grand
ODT
Mysql
PDF
Mysql cheatsheet - Part 2
PDF
Rootconf admin101
Locking Down Your MySQL Database.pptx
MySQL server security
My sql presentation
Mysql nowwhat
My sql with querys
Mysqldbatrainingsession12privilegesinmysql 170302152348
A Tour to MySQL Commands
Percona Live 2012PPT:mysql-security-privileges-and-user-management
Vansh Goel ISM (1).pptx
MySQL for beginners
MySQL DBA OCP 1Z0-883
Mysqlsecurityoptionsjan2021
Msql
Mysql grand
Mysql
Mysql cheatsheet - Part 2
Rootconf admin101

More from Combell NV (20)

PPTX
Play it extra safe! Kies een goede cyberverzekering
PPTX
Hoe gebruik je het resellerplatform als partner van Combell
PPTX
Managed WordPress bij Combell – wat doet dat precies?
PPTX
Back-ups: Hoe ze je kunnen redden van een cyberaanval
PPTX
Cyberaanvallen: Overzicht, gevolgen en beveiligingstips
PDF
Hoe gebruik je het resellerplatform als partner van Combell
PPTX
Hoe laat je jouw website scoren in zoekmachines zoals Google
PPTX
Een webshop bouwen in WooCommerce – advanced sessie
PPTX
Hoe start je een webshop met WordPress / WooCommerce
PDF
Keeping the cloud in check cvodmd
PDF
Hybrid cloud wiskyweb2012
PPTX
2012 03-27 developers e-commercedag presentatie5 ssl
PPTX
2012 03-27 developers e-commercedag presentatie2 drupal
PPTX
2012 03-27 developers e-commercedag presentatie1 magento
PPTX
2012 03-27 developers e-commercedag presentatie4 ogone
PDF
10 doe-het-zelf tips om aan e-commerce te doen
PDF
Develop and deploy using Hybrid Cloud Strategies confoo2012
PDF
Php through the eyes of a hoster confoo
PDF
Hybrid Cloud PHPUK2012
PPTX
2012 02-07 sql denali presentatie microsoft
Play it extra safe! Kies een goede cyberverzekering
Hoe gebruik je het resellerplatform als partner van Combell
Managed WordPress bij Combell – wat doet dat precies?
Back-ups: Hoe ze je kunnen redden van een cyberaanval
Cyberaanvallen: Overzicht, gevolgen en beveiligingstips
Hoe gebruik je het resellerplatform als partner van Combell
Hoe laat je jouw website scoren in zoekmachines zoals Google
Een webshop bouwen in WooCommerce – advanced sessie
Hoe start je een webshop met WordPress / WooCommerce
Keeping the cloud in check cvodmd
Hybrid cloud wiskyweb2012
2012 03-27 developers e-commercedag presentatie5 ssl
2012 03-27 developers e-commercedag presentatie2 drupal
2012 03-27 developers e-commercedag presentatie1 magento
2012 03-27 developers e-commercedag presentatie4 ogone
10 doe-het-zelf tips om aan e-commerce te doen
Develop and deploy using Hybrid Cloud Strategies confoo2012
Php through the eyes of a hoster confoo
Hybrid Cloud PHPUK2012
2012 02-07 sql denali presentatie microsoft

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Cloud computing and distributed systems.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Chapter 3 Spatial Domain Image Processing.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Cloud computing and distributed systems.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Managing a shared mysql farm dpc11