Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying password in MySQL connection string

I created ExpressJS MVC app using MySQL as DB with Yeoman generator and in config.js I want to change MySQL connection strings, but I don't know to specify password in string.

my string is mysql://root@localhost:3306/

Please help me.

like image 389
Aren Hovsepyan Avatar asked Aug 23 '16 15:08

Aren Hovsepyan


People also ask

How can I connect MySQL database with password?

Enter mysql.exe -uroot -p , and MySQL will launch using the root user. MySQL will prompt you for your password. Enter the password from the user account you specified with the –u tag, and you'll connect to the MySQL server.

How do I create a connection string in MySQL?

Driver={mySQL};Server=myServerAddress;Port=3306;Option=131072;Stmt=;Database=myDataBase;User=myUsername;Password=myPassword; The driver defaults to port value 3306, if not specified in the connection string, as 3306 is the default port for MySQL.


2 Answers

Here's generic connection-string parser, which offers a flexible optional syntax, while adhering to the URL syntax. Works in any environment.

const { ConnectionString } = require('connection-string');

const cs = new ConnectionString('mysql://user:password@host:port/dbName');
like image 55
vitaly-t Avatar answered Oct 21 '22 08:10

vitaly-t


Password and DB name also a part of connection string.
Ex: mysql://root:password@localhost:port/dbName

like image 29
Umair Ahmed Avatar answered Oct 21 '22 07:10

Umair Ahmed