How to Export MySQL Database From Digital Ocean Managed Database - mysql

I have a MySQL database hosted on Digital Ocean Managed Database service. I lost my previous dev machine and did not push the Schema to git along with application files. I am desperate to get back the SQL Schema in my local machine for further Development but have so far been usuccessfull. I have tried so many commands from different suggestions but they all failed.
I connect to the DB via the MySQL Shell using the command:
mysql -u username -password-h example-test-do-user-7878789-0.b.db.ondigitalocean.com -P 25060 -D example_db
All queries are executed successfully via this shell method. When trying to Dump the Schema to my machine, I use the following command:
mysql -u username -p -h mysql-test-do-user-4915853-0.db.ondigitalocean.com -P 25060 your_database_name \> database_file_name.sql
But I get the error as follows: mysqldump: unknown variable 'set-gtid-purged=OFF'
if I remove that part and try again, I get the error:
mysqldump: Got error: 2003: "Can't connect to MySQL server on 'localhost' (10061 "Unknown error")" when trying to connect
which doesnt make sense to me. So, without further ranting; How to I achieve my intended result.
NOTE: I did try Mysql workbench, but it won't connect all together

I can appreciate trying to achieve what you want via mysql shell. I stumbled across the same problem and for quite some tie did not find the help i needed, then I tried doing it using mysql workbench. Try it and you will find that its easier than usin the command-line approach. MySQL Workbench has a good GUI based database miguration capability. You can migrate you Do Managed DB directly into you local mysql server or export a schema dump. If you decide to go wit this approach, just make sure you add your machine's IP as a trusted source, else you will not be able to connect.

Related

How to setup and connect my database to NodeJS application on digital ocean

I have managed to create a droplet on Digital-Ocean and managed to clone my Node JS app onto it. Locally , the app connects to MySQL database and I wanted to the same on the live version. Ignorantly, I attempted to create a Managed database cluster which I did and added 1 user account and created 1 database. Right now I do not know how I can import the exported database.sql file into the database since I am only used to phpMyAdmin.
How can I get this to work and connect to my NodeJS app?
You were using phpmyadmin as an interactive Mysql client program. It's easy to use but hard to set up because it's a web app.
Try another MySql client program. The command-line client, memorably named mysql, is a good choice.
Get a shell on your droplet, then say
sudo apt install -y mysql-client
mysql -u username -p -h databasehostname -D database
mysql> source database.sql
mysql> quit
You'll be prompted for your database password.
That should import your database.
The mysql command line program is very useful and worth some of your time to learn to use.
First, make sure your database cluster is not open to the outside world by adding a DB firewall using DigitalOcean databases. You can allow connections from your own droplet's private IP address, and your own public address (or VPN or however way you're set up). Once you've done that, you should be able to import your SQL file locally (or from the DO Droplet, as long as you have the mysql client installed):
mysql -h [host-provided-do] -P [port-provided-do] -u [username-provided-do] -p [db-name-provided-do] < my-file.sql
The most important thing is to make sure your managed database is not open to the outside world, and that you make sure it only allows incoming connections from known IP addresses.
In your NodeJS app, you can set the driver to connect to the private subnet that DO provides.

Where can I run a mysql command line under Azure to fix "The used command is not allowed with this MySQL version (1148)"

I have a MySQL database which is hosted in Azure, and I have MySQL Workbench installed on my laptop. I want to do some importing from a CSV file located in my laptop, but whenever I try to that, I get an error message saying:
The used command is not allowed with this MySQL version
I did some online searching, and I found out that I need to run the following command:
mysql -u myuser -p --local-infile somedatabase
But, I don't know where I have to run it, and how, while as I said my database is hosted in Azure.
mysql is just the commandline executable of the MySql client. And most probably it is even part of the MySql workbech - just check the MySQL Workbech working folder. But the result will not be different is my guess.
The best way you can manage Import/Export for MySQL is to use a Free Tier WebSite and Install the phpMyAdmin extension.

MySQL Syntax Error (Ubuntu LAMP Server)

Alright, so I've got a fairly fresh Ubuntu (server) installation. Just finished installing the LAMP server and when I go to create a database I'm getting the generic syntax error (1064 / 42000).
My query:
CREATE DATABASE phpbb;
Pretty simple and pretty standard, so I'm not sure what the issue is. Any ideas?
It looks from your error like you're trying to execute SQL on the command line, something like:
mysql -u mike -p CREATE DATABASE phpbb';
MySQL isn't going to like that, it separates the initiation of the tool from the SQL commands.
What I'd normally do for CREATE DATABASE, as it's a one off, I'd do it manually.
So start the tool with
mysql -u mike -p
This should prompt you for your password, and connect to the local database, giving you a shell prompt:
mysql>
You then issue your
CREATE DATABASE phpbb;
If you want to run scripts from the command line, put them in a file and redirect the input to mysql. Usually you'd redirect the output too - something like this:
mysql -u mike -p < mysqlscript.sql > outputofscript.log

mysql workbench ssh custo command

I'm trying to configure a new connection through SSH tunnel.
But on the server, the command mysql does not exists. I have my own compilation called custo-mysql.
I mean, when I'm on the server, I use the following command :
$ custo-mysql -u root -pmypassword
How can I tell workbench to use custo-mysql and not mysql ?
mysql (and your custo-mysql) is a client for the server. Workbench is a client as well, so it doesn't need to use that custo-mysql thing. It just connects to your server.
Basically, on your server you have a "mysqld" running: a mysql server. Your commans custo-mysql connects to that server as a sort of interface. Workbench has the exact same function, so it should work if your networking/tunneling etc is correct.
As #Nanne already mentioned, you don't need the mysql client to connect to your MySQL server using Workbench.
I would just like to point out that Workbench does use the mysql command line client for importing databases in the Admin / Data Import/Restore section. Having said that, you'll certainly be OK without it for everything else.
Cheers,

Get database hosted on MySQL server

Im trying to create my own database with MySQL Workbench and run some queries on it. I have MySQL server 5.1 running and can enter queries in the command line tool to ask for version number and such.
But how do I get the server to host the database that I created in Workbench? When I enter "use MijnDatabase" or "-u root#localhost -p MijnDatabase" it says the database cannot be found. This makes sense, "MijnDatabase" the database file name and it's not connected to the server in any way (also tried with "mydb" wich is the db name I see inside Workbench).
Anyway I'm missing the link between MySQL server and hosting an actual database file.
When you create a database use only lower case letters and use underscore to separate words:
create database my_database;
use my_database;
show tables;
etc...
To connect to your database use:
mysql -u root -p
enter your password then
use my_database;
show tables;
etc...
I have not used MySQL Workbench but the command line and phpMyAdmin. I suggest you start using the command line to learn a little bit MySQL, then use a GUI tool. However the command line is your best teacher.
Have a look in the reference doc: http://dev.mysql.com/doc/refman/5.1/en/create-database.html
. Lean how to create a user and grant him permission on the database.