{"id":75,"date":"2012-09-21T08:30:27","date_gmt":"2012-09-21T08:30:27","guid":{"rendered":"https:\/\/www.nicktailor.com\/?p=75"},"modified":"2024-04-28T06:28:31","modified_gmt":"2024-04-28T06:28:31","slug":"plesk-mysql-queries","status":"publish","type":"post","link":"https:\/\/nicktailor.com\/tech-blog\/plesk-mysql-queries\/","title":{"rendered":"Plesk Mysql Queries Cheat Sheet"},"content":{"rendered":"<div><strong>I decided to blog this for people who use parallels plesk with mysql. I got some Parallel Certifications a couple years ago, this stuff will help you mine mysql information that you might need if your running a business.<br \/>\n<\/strong><\/div>\n<ol>\n<li>Domain Information<\/li>\n<li>Domains and IP addresses<\/li>\n<li>Domain Users accounts and passwords<\/li>\n<li>Client usernames\/passwords<\/li>\n<li>FTP accounts<\/li>\n<li>ftp users(with domain)<\/li>\n<li>Logrotate config for all domains<\/li>\n<li>DNS records for a domain<\/li>\n<li>DNS primary A-records for all domains<\/li>\n<li>Statistics application per domain<\/li>\n<li>SSL certificates installed under domains<\/li>\n<li>SSL certificate files associated with default domain on IP<\/li>\n<li>SSL certificate files associated with IP address<\/li>\n<li>SSL certificate files not in use by any domain<\/li>\n<li>Domains expiration in UNIX time<\/li>\n<li>Domains expiration in human readable time<\/li>\n<li>Bandwidth by service for the month(change date string accordingly)<\/li>\n<li>Disk usage per service by domain<\/li>\n<li>Mail Info<\/li>\n<li>Mail accounts<\/li>\n<li>All enabled mailboxes (local or redirect)<\/li>\n<li>List bounces<\/li>\n<li>List status of all mail to non-existent users:<\/li>\n<li>All (singular) email info<\/li>\n<li>List all Mail redirect\/forwards:<\/li>\n<li>List all Mail redirect\/forwards to external domains:<\/li>\n<li>Email Aliases<\/li>\n<li>Email Groups<\/li>\n<li>Email Autoresponders<\/li>\n<li>Mailbox quota size per domain:<\/li>\n<li>Databases<\/li>\n<li>Show databases by domain<\/li>\n<li>Show database users and passwords created in Plesk<\/li>\n<li>User Accounts<\/li>\n<li>ftp users(with domain):<\/li>\n<li>ftp users with additional details(shell,quota):<\/li>\n<li>database users(with domain):<\/li>\n<li>web users:<\/li>\n<li>subdomains usernames\/passwords:<\/li>\n<li>protected directories (htpasswd):<\/li>\n<li>One Time Use<\/li>\n<li>Redirect update from previous install<\/li>\n<\/ol>\n<p><em><strong>Domain Information<\/strong><\/em><br \/>\nDomains and IP addresses<br \/>\nselect domains.name,IP_Addresses.ip_address from domains,hosting,IP_Addresses where domains.id=hosting.dom_id and hosting.ip_address_id=IP_Addresses.id order by IP_Addresses.ip_address,domains.name;<br \/>\n<em><strong><br \/>\nDomain Users accounts and passwords<\/strong><\/em><br \/>\nmysql psa -uadmin -p`cat \/etc\/psa\/.psa.shadow` -e &#8216;select domains.name, accounts.password from domains, accounts, dom_level_usrs where domains.id=dom_level_usrs.dom_id and accounts.id=dom_level_usrs.account_id order by domains.name;&#8217;<\/p>\n<p>select domains.name,sys_users.login,accounts.password from domains,sys_users,hosting,accounts where domains.id=hosting.dom_id and hosting.sys_user_id=sys_users.id and sys_users.account_id=accounts.id order by domains.name;<\/p>\n<p><em><strong>Domain Users accounts and passwords and email.<\/strong><\/em><br \/>\nselect domains.name,sys_users.login,accounts.password,clients.email from domains,sys_users,hosting,accounts,clients where domains.id=hosting.dom_id and hosting.sys_user_id=sys_users.id and sys_users.account_id=accounts.id and clients.id=domains.cl_id order by domains.name;<br \/>\n<em><strong><br \/>\nClient usernames\/passwords<\/strong><\/em><br \/>\nselect clients.login, accounts.password from clients,accounts where clients.account_id=accounts.id;<br \/>\n<em><strong><br \/>\nFTP accounts<\/strong><\/em><br \/>\nmysql psa -uadmin -p`cat \/etc\/psa\/.psa.shadow` -e &#8216;select sys_users.home,sys_users.login,accounts.password from sys_users,accounts where sys_users.account_id=accounts.id order by home;&#8217;<br \/>\n<em><strong><br \/>\nftp users(with domain)<\/strong><\/em><br \/>\nselect domains.name,sys_users.login,accounts.password from domains,sys_users,hosting,accounts where domains.id=hosting.dom_id and hosting.sys_user_id=sys_users.id and sys_users.account_id=accounts.id order by domains.name;<br \/>\n<em><strong><br \/>\nLogrotate config for all domains<\/strong><\/em><br \/>\nselect domains.name,log_rotation.period_type,log_rotation.period,log_rotation.max_number_of_logfiles,log_rotation.turned_on from domains,dom_param,log_rotation where domains.id=dom_param.dom_id and dom_param.param=&#8221;logrotation_id&#8221; and dom_param.val=log_rotation.id;<br \/>\n<em><strong><br \/>\nDNS records for a domain<\/strong><\/em><br \/>\nselect domains.name,dns_recs.host,dns_recs.type,dns_recs.val from domains,dns_recs where domains.dns_zone_id=dns_recs.dns_zone_id and domains.name=&#8217;www.nicktailor.com&#8217;;<br \/>\n<strong><em><br \/>\nDNS primary A-records for all domains<\/em><\/strong><br \/>\nselect dns_recs.host,dns_recs.type,dns_recs.val from domains,dns_recs where domains.dns_zone_id=dns_recs.dns_zone_id and dns_recs.type=&#8217;A&#8217; and domains.name=substring_index(dns_recs.host,&#8217;.&#8217;,2) order by domains.name;<br \/>\n<em><strong><br \/>\nStatistics application per domain<\/strong><\/em><br \/>\nselect domains.name,hosting.webstat from domains, hosting where domains.id=hosting.dom_id;<\/p>\n<p><em><strong>List subdomains by domain<\/strong><\/em><br \/>\nselect subdomains.name,domains.name as domain from domains,sys_users,subdomains,accounts where domains.id=subdomains.dom_id and subdomains.sys_user_id=sys_users.id and sys_users.account_id=accounts.id;<\/p>\n<p>select subdomains.name,domains.name as domain from domains,sys_users,subdomains,accounts where domains.id=subdomains.dom_id and subdomains.sys_user_id=sys_users.id and sys_users.account_id=accounts.id and domains.name = &#8216;test.com&#8217;;<\/p>\n<p><em><strong>SSL certificates installed under domains<\/strong><\/em><br \/>\nselect domains.name as domain_name,IP_Addresses.ip_address,certificates.name as cert_name,certificates.cert_file from domains,IP_Addresses,certificates,hosting where domains.cert_rep_id != &#8220;NULL&#8221; and domains.id=hosting.dom_id and hosting.ip_address_id=IP_Addresses.id and domains.cert_rep_id=certificates.id;<\/p>\n<p><em><strong>SSL certificate files associated with default domain on IP<\/strong><\/em><br \/>\nselect domains.name as domain,IP_Addresses.ip_address,certificates.name,certificates.cert_file from domains,certificates,IP_Addresses where IP_Addresses.ssl_certificate_id=certificates.id and IP_Addresses.default_domain_id=domains.id order by domains.name;<\/p>\n<p><em><strong>SSL certificate files associated with IP address<\/strong><\/em><br \/>\nselect IP_Addresses.ip_address,certificates.cert_file from certificates,IP_Addresses where IP_Addresses.ssl_certificate_id=certificates.id;<\/p>\n<p><em><strong>SSL certificate files not in use by any domain<\/strong><\/em><br \/>\nselect IP_Addresses.ip_address,certificates.name,certificates.cert_file from certificates,IP_Addresses where IP_Addresses.ssl_certificate_id=certificates.id and IP_Addresses.default_domain_id &lt; 1 and certificates.name not like &#8220;%default%&#8221;;<br \/>\n<em><strong><br \/>\nDomains expiration in UNIX time<\/strong><\/em><br \/>\nselect domains.name, Limits.limit_name, Limits.value from domains, Limits where domains.limits_id=Limits.id and Limits.limit_name=&#8221;expiration&#8221; and Limits.value != -1;<\/p>\n<p><em><strong>Domains expiration in human readable time<\/strong><\/em><br \/>\nmysql psa -uadmin -p`cat \/etc\/psa\/.psa.shadow` -e &#8216;select domains.name, Limits.limit_name, from_unixtime(Limits.value) from domains, Limits where domains.limits_id=Limits.id and Limits.limit_name=&#8221;expiration&#8221; and Limits.value != -1;&#8217;<br \/>\n<em><strong><br \/>\nBandwidth by service for the month(change date string accordingly)<\/strong><\/em><br \/>\nselect domains.name as domain, SUM(DomainsTraffic.http_out)\/1024\/1024 as HTTP_out_MB, SUM(DomainsTraffic.ftp_out)\/1024\/1024 as FTP_out_MB, SUM(DomainsTraffic.smtp_out)\/1024\/1024 as SMTP_out_MB, SUM(DomainsTraffic.pop3_imap_out)\/1024\/1024 as POP_IMAP_out_MB from domains,DomainsTraffic where domains.id=DomainsTraffic.dom_id and date like &#8220;2009-10%&#8221; group by domain;<\/p>\n<p><em><strong>Disk usage per service by domain<\/strong><\/em><br \/>\nselect domains.name,disk_usage.*,httpdocs+httpsdocs+subdomains+web_users+anonftp+logs+dbases+mailboxes+webapps+maillists+domaindumps+configs+chroot as total from domains,disk_usage where domains.id=disk_usage.dom_id order by total;<\/p>\n<p><em><strong>Mail Info<\/strong><\/em><br \/>\n<em><strong>Mail accounts<\/strong><\/em><br \/>\nmysql psa -uadmin -p`cat \/etc\/psa\/.psa.shadow` -e &#8216;select concat(mail.mail_name,&#8221;@&#8221;,domains.name) as address,accounts.password from mail,domains,accounts where mail.dom_id=domains.id and mail.account_id=accounts.id order by address;&#8217;<\/p>\n<p>mysql&gt; select pname,email from clients;(list all clients name and emails)<\/p>\n<p><em><strong>All enabled mailboxes (local or redirect)<\/strong><\/em><br \/>\nSELECT mail.mail_name,domains.name,accounts.password,mail.postbox, mail.redirect, mail.redir_addr FROM mail,domains,accounts WHERE mail.dom_id=domains.id AND mail.account_id=accounts.id and (mail.postbox=&#8217;true&#8217; or mail.redirect=&#8217;true&#8217;) ORDER BY domains.name,mail.mail_name;<\/p>\n<p><em><strong>List bounces\u00a0If checking for backscatter, be sure to check for autoresponders too.\u00a0<\/strong><\/em><br \/>\nselect domains.name from domains,Parameters,DomainServices where DomainServices.type=&#8217;mail&#8217; and Parameters.value = &#8216;bounce&#8217; and domains.id = DomainServices.dom_id and DomainServices.parameters_id=Parameters.id order by domains.name;<br \/>\n<em><strong><br \/>\nList status of all mail to non-existent users:<\/strong><\/em><br \/>\nselect domains.name,Parameters.value from domains,Parameters,DomainServices where DomainServices.type=&#8217;mail&#8217; and Parameters.value in (&#8216;catch&#8217;,&#8217;reject&#8217;,&#8217;bounce&#8217;) and domains.id=DomainServices.dom_id and DomainServices.parameters_id=Parameters.id order by Parameters.value,domains.name;<br \/>\n<em><strong><br \/>\nAll (singular) email info<\/strong><\/em><br \/>\nSELECT mail.mail_name,domains.name,accounts.password,mail.redir_addr FROM mail,domains,accounts WHERE mail.dom_id=domains.id AND mail.account_id=accounts.id ORDER BY domains.name,mail.mail_name;<\/p>\n<p><em><strong>List all Mail redirect\/forwards:<\/strong><\/em><br \/>\nSELECT mail.mail_name,domains.name,mail.redir_addr FROM mail,domains WHERE mail.redirect=&#8217;true&#8217; AND mail.dom_id=domains.id AND mail.redir_addr!=&#8221; ORDER BY mail.mail_name;<\/p>\n<p><em><strong>List all Mail redirect\/forwards to external domains:<\/strong><\/em><br \/>\nSELECT mail.mail_name,domains.name,mail.redir_addr FROM mail,domains WHERE mail.redirect=&#8217;true&#8217; AND mail.dom_id=domains.id AND mail.redir_addr!=&#8221; AND SUBSTRING_INDEX(mail.redir_addr,&#8217;@&#8217;,-1) NOT IN (SELECT name from domains) ORDER BY domains.name,mail.mail_name;<br \/>\n<em><strong><br \/>\nEmail Aliases<\/strong><\/em><br \/>\nselect mail.mail_name, domains.name, mail_aliases.alias from mail, domains, mail_aliases where mail.dom_id=domains.id and mail.id=mail_aliases.mn_id;<\/p>\n<p><em><strong>Email Groups<\/strong><\/em><br \/>\nselect mail.mail_name as group_mailbox,domains.name,mail_redir.address as group_member from mail,domains,mail_redir where mail.dom_id=domains.id and mail.id=mail_redir.mn_id and mail.mail_group=&#8217;true&#8217; order by domains.name,mail.mail_name,mail_redir.address;<\/p>\n<p><em><strong>Email Autoresponders<\/strong><\/em><br \/>\nselect mail.mail_name, domains.name as domain, mail_resp.resp_name, mail_resp.resp_on, mail_resp.key_where as filter, mail_resp.subject, mail_resp.reply_to from mail,domains,mail_resp where mail.dom_id=domains.id and mail.id=mail_resp.mn_id and mail.autoresponder=&#8217;true&#8217; and mail_resp.resp_on=&#8217;true&#8217;;<\/p>\n<p><em><strong>Mailbox quota size per domain:<\/strong><\/em><br \/>\nselect domains.name,Limits.limit_name,Limits.value\/1024\/1024 as &#8220;quota MB&#8221; from domains,Limits where Limits.limit_name=&#8217;mbox_quota&#8217; and domains.limits_id=Limits.id;<br \/>\nDatabases<\/p>\n<p><em><strong>Show databases by domain<\/strong><\/em><br \/>\nselect domains.name as Domain, data_bases.name as DB from domains, data_bases where data_bases.dom_id=domains.id order by domains.name;<\/p>\n<p><em><strong>Show database users and passwords created in Plesk<\/strong><\/em><br \/>\nselect name,login,password from psa.db_users, psa.accounts, psa.data_bases where psa.db_users.account_id=psa.accounts.id and psa.data_bases.id=psa.db_users.db_id;<br \/>\n<em><strong><br \/>\nUser Accounts<\/strong><\/em><br \/>\nftp users(with domain):<br \/>\nselect domains.name,sys_users.login,accounts.password from domains,sys_users,hosting,accounts where domains.id=hosting.dom_id and hosting.sys_user_id=sys_users.id and sys_users.account_id=accounts.id order by domains.name;<\/p>\n<p><em><strong>ftp users with additional details(shell,quota):<\/strong><\/em><br \/>\nselect domains.name,sys_users.login,accounts.password,sys_users.shell,sys_users.quota from domains,sys_users,hosting,accounts where domains.id=hosting.dom_id and hosting.sys_user_id=sys_users.id and sys_users.account_id=accounts.id order by domains.name;<br \/>\n<em><strong><br \/>\ndatabase users(with domain):<\/strong><\/em><br \/>\nselect domains.name as domain_name, data_bases.name as DB_name,db_users.login,password from db_users, accounts, data_bases,domains where domains.id=data_bases.dom_id and db_users.account_id=accounts.id and data_bases.id=db_users.db_id order by domains.name;<br \/>\n<em><strong><br \/>\nweb users:<\/strong><\/em><br \/>\nselect domains.name, sys_users.login, web_users.sys_user_id from domains,sys_users,web_users where domains.id=web_users.dom_id and web_users.sys_user_id=sys_users.id;<br \/>\n<strong><em><br \/>\nsubdomains usernames\/passwords:<\/em><\/strong><br \/>\nselect subdomains.name,domains.name as domain, sys_users.login, accounts.password from domains,sys_users,subdomains,accounts where domains.id=subdomains.dom_id and subdomains.sys_user_id=sys_users.id and sys_users.account_id=accounts.id;<\/p>\n<p><em><strong>protected directories (htpasswd):<\/strong><\/em><br \/>\nselect domains.name, protected_dirs.path, pd_users.login, accounts.password from domains, protected_dirs, pd_users, accounts where domains.id=protected_dirs.dom_id and protected_dirs.id=pd_users.pd_id and pd_users.account_id=accounts.id;<\/p>\n<p><em><strong>One Time Use<\/strong><\/em><br \/>\n<em><strong>Redirect update from previous install\u00a0This was for an instance where redirects were brought over from a previous installation, but the previous migration failed to check if the redirects were active or not. This compares the two, and only updates the differences.\u00a0<\/strong><\/em><\/p>\n<p>UPDATE mail SET redirect=&#8217;false&#8217; WHERE id IN (SELECT mail_copy.id FROM mail_copy,domains WHERE mail_copy.redirect=&#8217;true&#8217; AND mail_copy.dom_id=domains.id AND mail_copy.redir_addr!=&#8221; and CONCAT(mail_copy.mail_name,&#8217;@&#8217;,domains.name) IN (SELECT CONCAT(mail.mail_name,&#8217;@&#8217;,domains.name) AS address FROM psa_orig.mail,psa_orig.domains WHERE mail.redirect=&#8217;false&#8217; AND mail.dom_id=domains.id AND mail.redir_addr!=&#8221;));<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I decided to blog this for people who use parallels plesk with mysql. I got some Parallel Certifications a couple years ago, this stuff will help you mine mysql information that you might need if your running a business. Domain Information Domains and IP addresses Domain Users accounts and passwords Client usernames\/passwords FTP accounts ftp users(with domain) Logrotate config for<a href=\"https:\/\/nicktailor.com\/tech-blog\/plesk-mysql-queries\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58,138,8],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-parallels-plesk"],"_links":{"self":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":18,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":1780,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/75\/revisions\/1780"}],"wp:attachment":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}