Applicable to:
- Plesk for Linux
- Plesk for Windows
Question
How to connect to MySQL and open the Plesk psa database?
Answer
Note: This guide is intended for Plesk administrators with SSH/RDP access to the server.
In Plesk Onyx/Plesk 12.x, use the plesk db
utility:
-
To access Plesk database in MySQL:
[root@server]# plesk db
Once you are logged in, start running SQL queries.
Example of an SQL query:
MYSQL_LIN: mysql> select id,name from domains where name='example.com';
+----+-------------+
| id | name |
+----+-------------+
| 3 | example.com |
+----+-------------+To exit MySQL, run the command:
MYSQL_LIN: mysql> quit
-
To run a query to Plesk database without logging in to MySQL:
[root@server]# plesk db "your_query_here"
Example:
[root@server]# plesk db "select id,name from domains where name='example.com'"
+----+-------------+
| id | name |
+----+-------------+
| 3 | example.com |
+----+-------------+
In Plesk 11.x and previous releases, use the following command:
-
To access Plesk database in MySQL:
[root@server]# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa
-
To run a query to Plesk database without logging in to MySQL:
[root@server]# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -e "select * from <table>"
On Windows Server, Plesk uses two MySQL instances:
- Plesk SQL Server on port 8306: for Plesk databases psa and apsc
- MySQL server on port 3306: for Horde, Sitebuilder and customers' databases
Accessing Plesk SQL Server
- On Plesk Onyx/Plesk 12.5, use the
plesk db
utility:-
To access Plesk database in MySQL:
C:\> plesk db
Once you are logged in, start running SQL queries.
Example of an SQL query:
C:\> mysql> select id,name from domains where name='example.com';
+----+-------------+
| id | name |
+----+-------------+
| 3 | example.com |
+----+-------------+To exit MySQL, run the command:
C:\> mysql> quit
-
To run a query to Plesk database without logging in to MySQL:
C:\> plesk db "your_query_here"
Example:
C:\> plesk db "select id,name from domains where name='example.com'"
+----+-------------+
| id | name |
+----+-------------+
| 3 | example.com |
+----+-------------+
-
-
In Plesk 12.0/Plesk 11.x and previous releases, use the following command:
-
To access Plesk database in MySQL:
C:\> "%plesk_dir%\MySQL\bin\mysql" -P8306 -uadmin -p psa
-
To run a query to Plesk database without logging in to MySQL:
C:\> "%plesk_bin%\dbclient" --direct-sql --sql="select * from <table>"
-
Accessing MySQL server
-
Run the following command:
C:\> "%plesk_dir%\MySQL\bin\mysql" -P3306 -uadmin -p
If the password is unknown, reset it according to this KB article.
Comments
3 comments
Note: In order to execute steps 6–8, in step 5 you must open Command Prompt by right-clicking and choosing Run As Administrator.
If you don’t, the connection will fail. See comments here: https://support.plesk.com/hc/en-us/articles/213909425-Is-there-a-root-user-in-MySQL-in-Plesk-
@Janus Bahs Jacquet
You are absolutely right, it is important to launch CLI as an Administrator.
This guide suggests that it is no longer possible to use any database tools (Workbench, Heidi, etc) to access in the PSA database in Obsidian, and that the only way is to RDP to the server and then connect to the psa database using the dedicated command line tool. Very safe no doubt, but it will make managing Plesk servers quite a bit harder! For example, it will not be possible any longer to export data from the Plesk database to CSV to analyse, and for example, removing defunct SSL certificates from domains that keep throwing errors and sending out emails will be an even bigger nightmare than it already is.
Please tell me I'm mistaken and there still a way to connect to the psa database using any regular MySQL tools?
Please sign in to leave a comment.