Home > database >  How to escape '@' from sign in username
How to escape '@' from sign in username

Time:01-18

I tried to connect to remote mysql server using mysqlsh, however the current username containers @ so

mysqlsh mysql://userid@salesdeparment:@123.45.678.123:3306/ ....

reported an error

Invalid URI: Illegal character [@] found at position xxx

Because the first @ is actually part of the username userid@salesdeparment, only second @ denote the server ip.

CodePudding user response:

When connecting to a remote MySQL server using the mysqlsh command-line client, you can use the mysqlx srv:// protocol to connect to the server using the DNS SRV records. This allows you to specify the server hostname and port in a single string and the client will automatically resolve the DNS SRV record to get the actual host and port.

Here is an example of how you can connect to a remote MySQL server using the mysqlx srv:// protocol and a DNS SRV record:

mysqlsh mysqlx srv://userid@salesdeparment:password@_salesdeparment._tcp.example.com/

Here, userid@salesdeparment is the encoded form of userid@salesdeparment . The @ is the URL encoded form of the @ character.

You can also use the --uri option to specify the connection details in the URI format:

mysqlsh --uri mysqlx srv://userid@salesdeparment:password@_salesdeparment._tcp.example.com/

You can also use --host and --port options to specify the host and port of the MySQL server respectively.

mysqlsh --host=123.45.678.123 --port=3306 --user=userid@salesdeparment --password=password
  • Related