I wanna run some commands from mysql shell remote, but when I run the command for example
mysql -u root -h remoteip -p
mysql> \! nano somefile.txt
mysql> \! python somescript.py
This command try to access to my michine, no the remote machine,
is there some way to run a native commands from mysql shell?
some like
mysql> select execute('python /tmp/script.py');
Note:
please dont tell me that use ssh because is special case when I just have access to mysql remote shell no more.
try this
mysqldump -u username -p -h remote.site.com DBNAME > backup.sql
to acheive the same you must have to create mysql use in remote server and should provide your machine ipadress.
As well make sure you can access mysql from your local machine.
GRANT SELECT,INSERT,UPDATE ON <dbname>.* TO
'<user>'#'ipaddressofm/cfromwhich you want to acess' IDENTIFIED BY '<password>';
Related
I have Mysql installed on my local PC and want to use mysqldump on my local pc to dump a remote database. So I open CMD and run the following command:
mysqldump -P 3306 -h 12.43.33.43 -u admin -p myDatabase > mydb.sql
So in the next line it should ask for my password? but instead i get the response 'Access is denied'. Am i missing something here?
ps.
If I try the following:
mysqldump -P 3306 -h 12.43.33.43 -u admin -p myDatabase
it will successfully ask for my password and start printing the dump in cmd, but this is no good as i need the response saved in a file.
I only wanted to know if you could connect.
The command is
mysqldump -P 3306 -h 12.43.33.43 -u admin -p --databases myDatabase --result-file=mydb.sql
As the connection is not secure, you send your credentials like a postcard, so that every one can read it.
Besides that having your server exposed to the internet, is very dangerous and can come to a disaster, so reconsider your security strategy and allow only access via ssh.
How can I do a mysqldump from a server by using the Terminal?
I did the following:
First of all I logged in:
ssh root#123.456.78.90 // then I enter my password
then I do:
mysql->show databases;
after that:
use the_database;
then I do:
mysqldump -u myusername -p the_database > db_backup.sql
after that, obviously, nothing happens and I do not get an error. So my question is, where does it save the backup and how can I get a the mysqldump on my local machine?
There are multiple ways of how and where to backup, but most probably you would not like to store your backup in the same server where you are running the database.
If you have ssh access to the server you could create an ssh-tunnel, the most basic example of this could be:
$ ssh -L 3307:localhost:3306 root#123.456.78.90
What this will do is to open port 3307 locally (just in case you already are using 3306) and forward it to localhost:3306 going through 123.456.78.90
Then you could do something like:
$ mysqldump -h localhost -P 3307 -u myusername -p the_database > db_backup.sql
To know your current path, run pwd it will print your current directory and in where the db_backup.sql will be created in case you don't specify and absolute path.
Without using ssh you could also try to connect directly by just specifying the host:
$ mysqldump -h 123.456.78.90 -u myusername -p the_database > db_backup.sql
In case the port is open probably you will need just to modify/grant the user permissions to allow your IP to access:
mysql> GRANT ALL ON the_database.* TO your_user#'123.456.78.90' IDENTIFIED BY 'secret';
Connect to your server using ssh command.
run below code
mysqldump -u userName -p databaseName > /path/to/backup.sql
the location path must be on same 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 have gone through similar cases listed here but it doesn't seem to work.
I was using MySQL Workbench to establish a connection with my database which is hosted on another server. Tried a few times and unable to connect followed by this error. I am confused as to where I should even do this flush. On PhpMyadmin under the SQL query? Cos when I tried to input the following command, it returns as syntax error. I am using a windows OS thus no shell shell scripting for me to input this information either. I am accessing the database temporarily via Cpanel/ phpmyadmin now.
Please help to tell where I should input this data and if my syntax is wrong. Thanks for help.
mysqladmin flush-hosts;
or
mysqladmin -umyname -pmypassword flush-hosts;
My error message as follows:
Failed to connect to MYSql at 192...* with user myName
Host 'host-92...*.as13285.net' is blocked because of many connection
errors; unblock with 'mysqladmin flush-hosts'
mysqladmin is not a SQL statement. It's a little helper utility program you'll find on your MySQL server... and "flush-hosts" is one of the things it can do. ("status" and "shutdown" are a couple of other things that come to mind).
You type that command from a shell prompt.
Alternately, from your query browser (such as phpMyAdmin), the SQL statement you're looking for is simply this:
FLUSH HOSTS;
http://dev.mysql.com/doc/refman/5.6/en/flush.html
http://dev.mysql.com/doc/refman/5.6/en/mysqladmin.html
You should put it into command line in windows.
mysqladmin -u [username] -p flush-hosts
**** [MySQL password]
or
mysqladmin flush-hosts -u [username] -p
**** [MySQL password]
For network login use the following command:
mysqladmin -h <RDS ENDPOINT URL> -P <PORT> -u <USER> -p flush-hosts
mysqladmin -h [YOUR RDS END POINT URL] -P 3306 -u [DB USER] -p flush-hosts
you can permanently solution your problem by editing my.ini file[Mysql configuration file]
change variables max_connections = 10000;
or
login into MySQL using command line -
mysql -u [username] -p
**** [MySQL password]
put the below command into MySQL window
SET GLOBAL max_connect_errors=10000;
set global max_connections = 200;
check veritable using command-
show variables like "max_connections";
show variables like "max_connect_errors";
You can easily restart your MySql service. This kicks the error off.
This is not a issue, just a curiosity which I couldn't find any answer for on mysql's reference or googling:
First of all I know that to connect to a database I would run on bash:
mysql -h myhost -u myusername -p
But if I just run the mysql command without parameters I have the mysql> prompt and on the help I can see that there's a 'connect' command. But you can't set the user or password, just the database and host so it will always deny the access naturally.
I also tried to run mysql with just the username and password parameters from bash (to specify the db and host later) but that don't work either. So, does the connect command work only if you ran mysql with the username and pass which are the same for another host? Or does it have more uses?
This is not secured but you can set mysql password on Unix shell as:
export MYSQL_PWD=secret
# then run mysql client to connect
mysql
mysql> connect somedb localhost
mysql> show tables
See MySQL Manual for list of environment variables
PS: mysql will use your unix user as mysql user for connecting. Alternatively you can set env variable USER on Windows or NetWare.