From my local computer, I can easily connect to a remote instance of mysql database using the mysql cli command (assuming environment variables are set):
# mysql -u root -p$DB_PASSWORD -h $DB_HOST --port=$DB_PORT
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7365
Server version: 5.7.14-google (Google)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.05 sec)
However, using docker it just hangs:
docker run --rm -it --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql \
mysql -u root -p$DB_PASSWORD -h $DB_HOST --port=$DB_PORT
mysql: [Warning] Using a password on the command line interface can be insecure.
show databases;
^C
^C
exit
exit
^C
and have to docker container stop mysql from another terminal window for it to exit the mysql container.
I tried even attaching to the container and run the same command to no avail. Tried connecting to an AWS MySQL instance and Google Cloud SQL instance, also tried to enter variables directly in the command line all with the same result. Why is it hanging and how can I make it work? Thanks!
Try expose the default port for MySQL
docker run -p 3306:3306 ...
I was using Google Cloud SQL and the IP address needed to be whitelisted for it to allow access. So adding that solved the connection issue.
I tried all the ways but below step has resolved my issue.
run command inside container
dpkg-reconfigure tzdata
it will ask you to select for Geographical area and Time zone, then you are done.
Related
I created a mlflow docker image, but I can't connect mysql database on another docker image. You can see a snippet of the script to start mlflow container.
...
DB_BACKEND="mysql+pymysql://${MLFLOW_USER}:${MLFLOW_PASS}#$IP:${MYSQL_PORT1}/mlflow"
MLFLOW_CMD="mlflow server --backend-store-uri ${DB_BACKEND} --artifacts-destination /mlartifacts --serve-artifacts -h 0.0.0.0 -p 5000"
docker run --rm \
--name mlflow-server \
-p 5000:5000 \
--volume ${DIR_SERVER}/artifacts:/mlartifacts \
-d mlflow-ubuntu-22.04:22110701 \
${MLFLOW_CMD}
When I check the logs I see these messages.
$ docker logs mlflow-server
2022/11/08 15:33:34 WARNING mlflow.store.db.utils: SQLAlchemy engine could not be created. The following exception is caught.
(pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '172.17.0.2' ([Errno 111] Connection refused)")
(Background on this error at: https://sqlalche.me/e/14/e3q8)
Operation will be retried in 0.1 seconds
I can connect mysql from mlflow docker image with my user/password and I have permission to create a table without problems.
$ docker exec -it mlflow-server bash
root#b68c447b5ce9:/# mysql -u mlflow -p -h 172.17.0.2 mlflow
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2413
Server version: 8.0.31 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE TABLE test(id int);
Query OK, 0 rows affected (0.91 sec)
mysql> show tables;
+------------------+
| Tables_in_mlflow |
+------------------+
| test |
+------------------+
1 row in set (0.01 sec)
mysql> drop table test;
Query OK, 0 rows affected (0.41 sec)
mysql>
How do I fix the connection with Mysql server? How do I debug the mlflow connection?
Best regards,
I have MariaDB (foobar_db) running in local environment in Docker. I have a SQL file some_sql_dump.sql that I want to run on this database. This is what I tried:
docker exec -t container_id_here mysql -u root -prootpass foobar_db < some_sql_dump.sql
This takes me into MariaDB's monitor:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.4.13-MariaDB-1:10.4.13+maria~bionic mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [foobar_db]>
It seems like using the arrow (<) to pass in input from some_sql_dump.sql did not work correctly. Why did the arrow not work, and how can I make it run the SQL from the file?
I have just used the "--interactive , -i" option and it seems to work.
$ docker exec -i {container_id} mysql -u root -prootpass foobar_db < some_sql_dump.sql
Which specific JDBC driver am I missing below?
nicholas $
nicholas $ basex mysql.xq
Stopped at /home/nicholas/flwor/mysql.xq, 3/9:
[sql:init] Could not find driver: com.mysql.jdbc.Driver
nicholas $
nicholas $ cat mysql.xq
xquery version "3.0";
sql:init("com.mysql.jdbc.Driver"),
let $con := sql:connect("jdbc:mysql://localhost:3306/northwind")
return sql:execute($con, "SELECT first_name FROM customers LIMIT 3;")
nicholas $
nicholas $ mysql -h localhost -P 3306 --protocol=tcp -u user -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2901
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> SELECT first_name FROM northwind.customers LIMIT 3;
+------------+
| first_name |
+------------+
| Alexander |
| Amritansh |
| Andre |
+------------+
3 rows in set (0.00 sec)
mysql>
I've tried installing a few JDBC results from looking through apt on Ubuntu, but it looks like I probably need to connect those up with BaseX so that they're picked up.
And, incidentally, I would presumably need to send a user and password to run the above query, specific to MySQL?
You need to install the appropriate JAR, and add it to your classpath.
Using packaged drivers:
sudo apt install libmariadb-java
Edit your mysql.xq file to load org.mariadb.jdbc.Driver instead of com.mysql.jdbc.Driver, and run basex with the following command:
JAVA_CLASSPATH=/usr/share/java/mariadb-java-client.jar basex
Authentication information can be provided in various ways, e.g. using parameters in the connection string, and/or information in the MariaDB/MySQL client configuration file.
I am a new user on Stack Overflow, so I apologize in advance for any potential breaches of site etiquette.
I am attempting to create a BASH script that will generate a command to invoke the MariaDB monitor, i.e. mysql. I want this mysql command to include the --init-command option. I want the --init-command option to set a list of user variables to a their values, as specified in a configuration file.
The script builds a string that appears to be correct for my purpose but, when it invokes mysql, an error is generated. If I print out the generated string from the script, it appears to be exactly what I was attempting to create.
I have boiled it down to the following code example:
#!/bin/sh
declare foo="name"
declare bar="value"
declare invoke="mysql -p -D information_schema"
declare opts=" --init-command='SET #$foo:=\"$bar\"'"
invoke+=$opts
echo $invoke
$invoke
When I execute this script, the result looks like:
$ example.sh
mysql -p -D information_schema --init-command='SET #name:="value"'
Enter password:
ERROR 1044 (42000): Access denied for user 'Bill'#'%' to database '#name:="value"''
This error message doesn't even seem to make sense.
However, if I copy the generated command, and paste it back into the command prompt, it requests my password, and proceeds as I would expect, as follows:
$ mysql -p -D information_schema --init-command='SET #name:="value"'
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 171
Server version: 10.3.11-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [information_schema]> SELECT #name;
+-------+
| #name |
+-------+
| value |
+-------+
1 row in set (0.000 sec)
MariaDB [information_schema]>
Demonstrating that the SET command in the --init-command option was successfully passed to the MariaDB monitor, and executed.
I do not know whether this is a Linux issue, a BASH issue, or a MariaDB issue. So, while I have spent a good amount of time trying to find the answer, I really don't know where the problem originates, and therefore, where to focus my research.
Please note: I only used the information_schema database in my example because I expect that anyone attempting to recreate this problem would have that database available to them.
Thank you in advance for your assistance.
Some options:
Option 1:
#!/bin/sh
# USING BASH
# FILE: bash_mariadb.sh
foo="\`name\`"
bar="value"
mysql -p -D information_schema --init-command="SET #$foo:='$bar';"
Option 2:
#!/bin/sh
# USING BASH
# FILE: bash_mariadb.sh
foo="\`name\`"
bar="value"
opts=(--init-command="SET #$foo:='$bar';")
invoke=(mysql -p -D information_schema "$opts")
"${invoke[#]}"
Option 3:
#!/bin/sh
# USING BASH
# FILE: bash_mariadb.sh
foo="\`name\`"
bar="value"
#define
invoke() {
opts=(--init-command="SET #$foo:='$bar'")
if [[ -v opts ]]; then
invoke=(mysql -p -D information_schema "$opts")
else
invoke=(mysql -p -D information_schema)
fi
"${invoke[#]}"
}
#call
invoke
Option 4: DANGER, option not recommended for safety reasons.
#!/bin/sh
# USING BASH
# FILE: bash_mariadb.sh
foo="\`name\`"
bar="value"
invoke="mysql -p -D information_schema"
opts=" --init-command='SET #$foo:=\"$bar\"'"
invoke+=$opts
eval $invoke
In all cases:
$ ./bash_mariadb.sh
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 10.3.11-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [information_schema]> SELECT #`name`;
+---------+
| #`name` |
+---------+
| value |
+---------+
1 row in set (0.000 sec)
Welcome to SO.
From a script you have to indicate the password you want to use.
The option -p force it for a interactive introduction of the password, wich don't works from a script.
If you instead use -ppassword (notice that you still write the "p", only that you write it next to the password, without spaces), your connection will work.
So, you just have to modify the line:
declare invoke="mysql -ppassword -D information_schema"
(Don't forget to write your password where I wrote "password", of course :) )
When I start mysql using System Preferences>MySQL>StartMySQLServer, then I can do this:
/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$ ./mysql -uroot -p
Enter password: <password shown me during installation>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.10
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'my new password';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql>
And I can see the mysql process created by System Preferences>MySQL>StartMySQLServer:
/Library/LaunchDaemons$ ps -e | grep mysql
1735 ?? 0:00.31 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid
1743 ttys000 0:00.00 grep mysql
/Library/LaunchDaemons$
But after stopping the server using System Preferences>MySQL, I am unable to start the mysql server using the command line (following the instructions in the docs):
/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$ sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$ ./mysql -uroot -p
Enter password: <new password>
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
There's no mysql process:
/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$ ps -e | grep mysql
1920 ttys001 0:00.00 grep mysql
/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$
How are you supposed to start the mysql server from the command line?
You have to start the mysql server first before you can connect. I think you you must start mysqld daemon but i am not sure
I use following command on terminal to start mysql:
mysql.server start
Give it a try.
Actually, the answer you want is:
1.first, add your mysql path to ~/.bash_profile:
export PATH=${PATH}:/usr/local/mysql/bin
Save it and open a new terminal.
2.Then, you can start/stop/restart mysql by,(you can also choose to start it from the "mysql" in "system preferences" or to forget it):
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server restart
3.After you start, use command "mysql" at your will~