I'm trying to query remote database with the following script.
some_db="somedb"
isAnythingToProcess=$(mysql -uroot -proot -D$some_db -e "$checkSearch");
This works for me locally however whenever i try to run bash script to remote AWS server I get error
ERROR 1049 (42000): Unknown database 'somedb'
Any hints?
P.S. The database exists for sure. I can connect to it via MySQL client.
You need to add the parameter for remote host -h
some_db="somedb"
isAnythingToProcess=$(mysql -uroot -proot -h REMOTE_IP -D$some_db -e "$checkSearch");
Related
I am connecting to database mysql using command prompt using below command
mysql -h localhost -u test -ptest test;
But i am getting following error:-
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
-h localhost -u test -ptest test' at line 1
I have done a lot of googling but could not find the reason behind this problem. Any help?
It seems you are executing the statement at mysql command line console but not at system shell prompt.
The statement
mysql -h localhost -u test -ptest test;
is for system shell prompt.
And while running at command prompt, you don't need to terminate the command by a semi colon.
And for suppressing use of password at command line,
change
-ptest
to
-p
It then prompts you to input your password.
You need to run that command (which starts the mysql shell) from the command prompt.
You are trying to run it inside the mysql shell.
First make sure your command line doesnt show
mysql>
prefix. if it shows you are already in the mysql console.
you have to type the command outside the mysql console.
mysql -h localhost -u test -ptest
That will fix you issue.
Refer Mysql documentation for more information
http://dev.mysql.com/doc/refman/5.0/en/connecting.html
Thanks.
mysql -u root -p -h localhost
then command would ask for password, input it and you can logged into mysql server
I am trying to connect to MySQL database from MySQL shell on windows.
No matter what I type in MySQL shell, it keeps giving me error : 'Not connected'.
Query eg 1 : mysql --host=localhost --port=3306 --user=root -p;
Query eg 2 : mysql -u root -p
O/P : ERROR: Not connected
I have MySQL server installed on my machine. Also MySQL service is running in the background.
Also, I was able to connect from MySQL workbench.
ERROR MESSAGE
MySQL Workbench Connection
My temporary workaround is that I make use of ssl protocol to connect to MySQL server :
MySQL> \connect root#localhost
MySQL localhost:33060+ ssl SQL > show databases;
The first step is that you need to check if you are in the MYSQL Shell SQL mode or JS mode.
Then if you are in SQL mode then you are good to go else you need to switch to SQL mode by this command
\sql
The next step is to connect using this command
\connect root#localhost
In your case, you might have given the privilege as the IP address so you need to check your localhost IP which can be done by this command in your command prompt.
ipconfig and then just check the IP address and put it in place of localhost in the previous command. If this still doesn't works then put 127.0.0.1:3306.
After this, it will prompt to add or save the password , enter a unique password there.
After this you are good to go and check the user and localhost after this by this command
SELECT user, host FROM mysql.user;
Try mysql -u root -p
I haven't used MySQL shell, I typically use gitbash and it works just fine
I had faced the same issue on my Windows 10 machine with MySQL 5.7 and the following commands helped me:
mysqlsh.exe - to open mysql shell; then
\sql - to start working with SQL;
finally:
\connect root#127.0.0.1:3306
You can use:
mysql -uroot -hlocalhost -P3306 -p
or
mysql -uroot -h127.0.0.1 -P3306 -p
or
mysql -uroot -p
I am exploring Google Cloud SQL and I need to have the ability to merge data bases for continuous integration reasons but I cannot figure out how (on a Cloud SQL instance).
The instance contains three databases: development, staging, and production.
I would usually run a simular command on a server instance running MySQL with the following:
mysqldump -n -t -u <myUSER> --password=<myPASSWORD> development | mysql -u <myUSER> --password=<myPASSWORD> staging
If I try to run this command via a server instance that has access to the (remote) dB instance, I get the following error:
mysqldump: Got error: 1045 (28000): "Access denied for user
'myUSER'#'localhost' (using password: YES)" when trying to
connect
I am thinking I need to pass an IP address in the command(??) - But I do not know how.
SO my question is how would I connect to a Google Cloud SQL instance via another server instance that has permissions to access the (remote) database server?
Any help will be greatly appreciated!
-j
I just needed to pass -h <DB-IP> in the command.
i.e.:
mysqldump -n -t -u <myUSER> -h <XXX.XXX.XX.XXX> -p<myPASSWORD> development | mysql -u <myUSER> -h <XXX.XXX.XX.XXX> -p<myPASSWORD> staging
I'm using linux command line to access amazon rds mysql, however, i keep getting the Unknown MySQL host error.
here is the command:
mysql -uxxx -pxxxx -hmydb.xxxx.us-west-2.rds.amazonaws.com:3306
I have added MySQL rule in the security group, but it still does not work.
Or try:
mysql -u xxx -p xxxx -h mydb.xxxx.us-west-2.rds.amazonaws.com --port=3306
I have tried the following command syntax to connect with live
database...
-u Username -pPassword -h HostName Database Name
But there is an error
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MYSQL server version for the right
syntax to use near ' -u Username -pPassword -h HostName Database Name'
The command you're describing is for connecting to the database in command line. If you need to connect to a database inside a PHP script, you must use:
mysqli_connect aka mysqli::__construct
PDO::__construct
I'm not recommending it but if you're stuck with legacy code, mysql_connect also does the same for the deprecated mysql_* extension.
Try this... This might help you
connect to mysql database using command line and php
You must be using this command already on mysql shell prompt or on phpmyadmin like sql frontend. You must not use this command on mysql-shell as you are already loggin into mysql. Try this command on bash shell on linux or dos prompt on windows.
mysql -u Username -pPassword -h HostName DatabaseName
One more thing, If you are using windows (like wamp/xampp). You may need to pass full mysql path like
c:\wamp\bin\mysql\mysql -u Username -pPassword -h HostName DatabaseName