I would like to facilitate opening a database UI for development projects (usually docker containers, bound to arbitrary ports on the host machine) by a generic command.
I wonder if it is possible to open MySQL Workbench and let it connect automatically from the command line.
Similar to giving connection parameters with the mysql console:
mysql --host=127.0.0.1 --port=$port --user=db --password=db db
I haven't found that specifically in the supported arguments, so either it is hidden or maybe possible with any of the other options?
EDIT:
Probably the way is to generate a file to pass to --query dynamically?
Here's the format for the mysqlworkbench --query parameter:
--query="$user:$password#$host:$port"
This feature already exists as an example in ddev - look in the ~/.ddev/commands/host/mysqlworkbench.example file. (See on github).
For ddev, the query is set up as query="root:root#127.0.0.1:${DDEV_HOST_DB_PORT}", which uses the root/root credentials, accesses the 'db' container via localhost on the port provided by ddev at $DDEV_HOST_DB_PORT.
Related
Does the MySQL Command Line Interface (CLI) or "shell" offer the ability to establish a connection using environment variables? The PostgreSQL CLI psql does via libpq with connection variables:
PGHOST
PGPORT
PGDATABASE
PGUSER
PGPASSWORD
I know I can connect via command-line switches and a ~/my.cnf file, but I'm wondering if there is an environment variable option analogous to the way psql works. Thanks!
Yes, for some of them: https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html
MYSQL_HOST
MYSQL_TCP_PORT
There is no environment variable for the schema to use as the default schema. Client should specify that in the connection DSN, or else the USE schema statement after connecting.
There is no environment variable for the MySQL username.
MYSQL_PWD but this is deprecated and insecure and will be removed in a future version of MySQL. It's insecure for PostgreSQL for the same reason: another user can view your client's environment variables using ps.
It's more secure to use ~/.my.cnf, or you can specify a different option file to use. You can even store the username/password in an encrypted options file. See https://dev.mysql.com/doc/refman/8.0/en/option-files.html
MySQL workbench has a handy connection option - 'standard TCP/IP over SSH'. This allows me to connect to a publicly-inaccessible MySQL server (let's call it mysql#private.com), by SSH-ing onto a remote server (let's call it myserver#public.com) that is on the same network as the MySQL server.
I am trying to re-create this using the MySQL command line client and persistently failing. I have tried opening an SSH tunnel to forward port 3306 from myserver#public.com, to 127.0.0.1 (ie, localhost). This does not work, because at no point have I specified where to find mysql#private.com.
I presume MySQL workbench must pull off this handy trick via some combination of the MySQL client CLI and generally-availble tools like SSH. If anyone could show me how it's done, I'd be most grateful.
As is customary with SO I googled for about three hours before posting this question then found the answer within about three minutes of posting it. There is a detailed guide here:
https://medium.com/#deepspaceprog/how-to-connect-via-ssh-to-an-amazon-rds-instance-running-postgresql-5e7661cdd37e
That says it better than I can but the critical command is this:
ssh -N -L 3306:mysql#private.com:3306 myserver#public.com
If I paraphrase this into English, I believe it might say
"ssh into myserver#public.com; forward port 3306 on the local connection mysql#private.com to 3306 on the local machine".
I'm currently using mod_dbd (module provided by Apache and manage DB connection)
but I can't find a way to connect to ssl enabled MySQL
I'm using ap_dbd_open function to get db handle
(https://github.com/apache/httpd/blob/trunk/modules/database/mod_dbd.c#L793)
Is there any way to connect to SSL enabled MySQL with mod_dbd module?
You can accomplish this using MySQL options files. First, make up a group name and add it to your DBDParams, e.g. DBDParams "host=somehostname dbname=apache user=apache pass=somepassword group=websvr"
Then, put a group with the same name in a MySQL options file with a colon-separated list of supported ciphers, like this:
[websvr]
ssl-cipher=ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA
Typically your options file will be /etc/mysql/my.cnf. Check your MySQL or MariaDB C-Connector documentation for where options files are located on your platform.
The example above has a short list of two ciphers, but if you have OpenSSL - you can get a full list of supported ciphers with: $ openssl ciphers
If you can connect to your databse interactively with $ mysql --ssl --host=somehostname, you can show the supported list of ciphers and the cipher currently being used with mysql> SHOW STATUS LIKE 'ssl_cipher%';
One word of caution: If your server is started as root, but then changes to an unprivileged user ID with the User Directive, don't choose the options file ~/.my.cnf because once the uid is changed your application will not be able to access /root/.my.cnf.
I am trying to understand PCF concepts and thinking that once i am done with creating mysql services in PCF, how i can manage that database like creating tables and maintaining that table just like we do in pur traditional environment using mySqldeveoper. I came across one service like PivotalMySQLWeb and tried but didnt liked it much. So if somehow i can get connection details of mysql service , i can use that to connect using sql developer.
The links #khalid mentioned are definitely good.
http://docs.pivotal.io/p-mysql/2-0/use.html
https://github.com/andreasf/cf-mysql-plugin#usage
More generally, you can use an SSH tunnel to access any service, not just MySQL. This also allows you to use whatever tool you would like to access the service.
This is documented here, but if for some reason that goes away here are the steps.
Create your target service instance, if you don't have one already.
Push an app, any app. It really doesn't matter, it can be a hello world app. The app doesn't even need to use the service. We just need something to connect to.
Either Bind the service from #1 to the app in #2 or create a service key using the service from #1. If you bind to the app, run cf env <app> or if you use a service key run cf service-key MY-DB EXTERNAL-ACCESS-KEY and either one will give you your service credentials.
Run cf ssh -L 63306:us-cdbr-iron-east-01.p-mysql.net:3306 YOUR-HOST-APP, where 63306 is the local port you'll connect to on your machine and us-cdbr-iron-east-01.p-mysql.net:3306 are the host and port from the credentials in step #3.
The tunnel is now up, use whatever client you'd like to connect to your service. For example: mysql -u b5136e448be920 -h localhost -p -D ad_b2fca6t49704585d -P 63306, where b5136e448be920 and ad_b2fca6t49704585d are the username and database name from step #3 and 63306 is the local port you picked from step #4.
Additionally, if you want to connect aws-rds-mysql (instantiated from Pivotal Cloud Foundry) from IntelliJ, you can use the DB-Navigator Plugin (https://plugins.jetbrains.com/plugin/1800-database-navigator) inside IntelliJ, through which, database manipulation can be performed.
After creating the ssh tunnel $ cf ssh -L 63306:<DB_HOSTNAME>:3306 YOUR-HOST-APP (as also mentioned in https://docs.pivotal.io/pivotalcf/2-4/devguide/deploy-apps/ssh-services.html),
Go to DB Navigator plugin and click on custom under new connection.
Enter the URL as: jdbc:mysql://:password>#localhost:63306/<database_name>
The following thread might be helpful for you as well How do I connect to my MySQL service on Pivotal Cloud Foundry (PCF) via MySQL Workbench or CLI or MySQLWeb Database Management App?
I'm trying to save Asterisk's CDR to an external mysql host.
I've modified the the connection details in the FreePBX advanced settings section,
and I also tried editing the cdr_mysql.conf file in /etc/asterisk,
but FreePBX still can not connect to the external mysql host.
When I'm trying to log into the UCP I get the failed to connect DB with the connection string.
It looks like the string FreePBX tries to connect with is wrong, becuase when I set up a test .NET web site to try and open a connection to mysql it works, but I am using a different syntax in the connection string.
BTW, I can telnet the external host from my pbx machine and I know for sure that this is not a network issue.
How can I have my CDR saved to an external mysql host?
**Edit: I also copied the db structure from the original mysql server so it won't be an issue.
Thank You!
Check connection string, check firewall
You can use
mysql -h hostname -u user -ppassword databasename
from command line to check connection is really allowed and no firewall.
You can get db access info from /etc/amportal.conf or /etc/asterisk/freepbx.conf
If you still have issues after that check, you can enable debug in logger.conf