Applicable to:
- Plesk for Linux
- Plesk for Windows
Question
A database exists in a database server, but is absent in Plesk at Domains > example.com > Databases.
How to register an existing database in Plesk?
Answer
Below are common examples of registering existing databases.
To see all available commands for registering existing databases, see:
-
For Linux:
Reference for Command-Line Utilities, Plesk for Linux: database -
For Windows:
Reference for Command-Line Utilities, Plesk for Microsoft Windows: database.exe
-
Connect to a Plesk server via SSH.
-
Register an existing database in Plesk with the command:
# plesk bin database --register db_name -domain example.com -server 203.0.113.2:3306
where:
- db_name - a database name
- example.com - a domain name to which the database is going to be attached
- 203.0.113.2:3306 - an IP address of a MySQL server and its port. Use localhost:3306 if this is a local MySQL server.
-
Register an existing database user with the command:
# plesk bin database --register-dbuser db_user -domain example.com -database db_name -type mysql -user-role readWrite -passwd "<password>" -server 203.0.113.2:3306
where:
- db_user - a database username
- example.com - a domain name specified on step 2
- db_name - a database name specified on step 2
- <password> - a password of the database user
- 203.0.113.2:3306 - an IP address of a MySQL server and its port. Use localhost:3306 if this is a local MySQL server.
-
Connect to a Plesk server via RDP.
-
Make sure that a database server is registered in Plesk at Tools & Settings > Database Servers.
-
With the command below, register a database in Plesk and assign it to a domain:
C:\> plesk bin database.exe --register db_name -domain example.com -server 203.0.113.2
where:
- db_name - a database name
- example.com - a domain name to which the database is going to be attached
- 203.0.113.2 - an IP address of a remote database server. It can also be a hostname
-
Register a database user in Plesk and assign it to the database:
C:\> plesk bin database.exe --register-dbuser db_user -domain example.com -database db_name -type mssql -user-role readWrite -passwd "<password>" -server 203.0.113.2
where:- db_user - a database username
- example.com - a domain name specified on step 4
- db_name - a database name specified on step 4
- mssql - a type of the MSSQL database. To register a MySQL database, use mysql
- <password> - a password of the database user
- 203.0.113.2 - an IP address of a remote database server. It can also be a hostname
Comments
5 comments
An additional information is valid, if you have more than one database server to map, for the second command is necessary set as default on which server the database is present, 'Tools & Settings > Database Servers > db server > Settings > Use this server as default for MS SQL`. In such conditions it is possible to explicitly specify the server in the command by adding `-server server.host.name`, for example:
# plesk bin database --register-dbuser db_user -domain example.com -database db_name -type mysql -user-role readWrite -passwd <password> -server server.host.name
I am preparing my 12.5 instance to be migrated to Onyx on a new server and this guide helped me a lot!
In one case I experienced an issue where an existing mysql user is in the format user.name
The error I'm getting is always "Database user name is invalid." even if I'm putting the name in single or double quotes. Is there a way I can make the tool accept that type of user name?
Hi, @Simon.
I have just checked this on Plesk Onyx 17.8, and I was able to use such usernames. I created database 'test' and database user 'test.test' and was able to register both database and database user:
# plesk bin database --register test -domain example.com -server localhost
The database was successfully registered.
# plesk bin database --register-dbuser test.test -domain example.com -database 'test' -type mysql -user-role readWrite -passwd ****
The database user was successfully registered.
Could you please share the steps you are taking with a little bit more details?
Well then it's probably fixed already in Onyx. As I mentioned I'm coming from 12.5 and that is where I experienced the issue when trying to get all DBs and users registered properly before the migration.
I could move on by just renaming the user to something without a dot.
@Simon
This is expected behavior for Plesk 12.5. It is not possible to create database user with '.' character in the name in Plesk 12.5.
Please sign in to leave a comment.