Search code examples
mysqlrustdatabase-connectionrust-diesel

diesel_cli setup returns error regarding DATABASE_URL


I am trying to setup Diesel-CLI but it always returns some error regarding DATABASE_URL.

For this question, Let's assume:

  • user=root
  • password=#Abcd1234
  • host=localhost
  • database=codeforces
  • mysql server socket=/var/lib/mysql/mysql.sock/


For DATABASE_URL=mysql://root:#Abcd1234@localhost/codeforces  
and DATABASE_URL=mysql://root:#Abcd1234@localhost/codeforces.sql?socket=(/var/lib/mysql/mysql.sock)

Error: Unknown MySQL server host 'root' (-2)

For DATABASE_URL=mysql://root@localhost/codeforces  
and DATABASE_URL=mysql://root@localhost/codeforces?socket=(/var/lib/mysql/mysql.sock)

Error: Can't connect to local MySQL server through socket '/run/mysql/mysql.sock' (2)

For DATABASE_URL=mysql://root@127.0.0.1/codeforces

Error: Access denied for user 'root'@'localhost' (using password: NO)

For DATABASE_URL=mysql://root:#Abcd1234@127.0.0.1/codeforces

Error: Unknown MySQL server host 'root' (-2)


I have tried googling it but no results so far. I don't know where i am making the mistake.

So my question is:
How to reslove this error?


Solution

  • My DATABASE_URL was not working because i was using reserved characters in the url.

    From RFC 1738 specification:

    Only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

    For those who are getting this error on changing 'localhost' to '127.0.0.1' :

    Error: Plugin caching_sha2_password could not be loaded: /usr//usr/lib64/mysql/plugin//caching_sha2_password.so: cannot open shared object file: No such file or directory

    Try doing this(It worked for me):

    mysql>ALTER USER 'yourusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';