Getting error when use dumped database in Navicat - mysql

I have multiple heavy databases (+3M records) and about +40 functions, procedures, and events.
I want to get a backup before doing the process on the database. backup is successfully done but when I want to use it in a new and transparent database Navicat says finished with errors.
here :
the new database has the same Character set and same collection.
but when I use the command line to get back up mysqldump dbname > bak.sql and import it with MySQL new_dbname < bak.sql finished successfully BUT without function and procedures.
how can I fix it? Thanks.

Related

Restore database from dump using mysql script

I'm testing a python script that requires me to manually clear and restore a fresh copy of my database for the purposes of debugging it. Basically each time the script cracks up, it breaks my database and I need a fresh copy. It would be really convenient if I could just run a sql script to so so. This is trivial except for the part when I re-import the data from a file on my machine; I can't seem to figure out how to do that within the sql script.
I can do it by clicking through the GUI as detailed here.
And I can do it by running this in the terminal
mysql -u root -p testdb < filename.sql
But what I would really like to do is to throw a line in my sql script along with my drop and create commands. Something like this
drop schema testing2;
create database testing2;
use testing2;
some command to restore from ....\Dump20230125.sql
I read here that I could use source ....\Dump20230125.sql but mysql workbench throws a syntax error and says that "source is not valid at this position"
Is there a way to accomplish what I'm after?

mysqlsh to dump and load full schema

I want to use mysqlsh to do the following:
Dump the FULL schema of a given database (not just tables, but functions, triggers, everything related to this database schema, same as mysqldump -R DATABASE > DATABASE.sql)
Load this full schema into a brand new database I just created (similar to mysql --database=NEWDATABASE < DATABASE.sql)
When I run mysqlsh --execute 'util.dumpTables("DATABASE", [], "SQL/DATABASE", {all:true});', it of course just dumps the tables, and this can easily be imported into a brand new database with this command mysqlsh --database=NEWDATABASE --execute 'util.loadDump("SQL/DATABASE", {schema: 'NEWDATABASE', ignoreVersion:true,resetProgress:true});. The problem is it is missing the functions and stored procedures.
So then I tried mysqlsh --execute 'util.dumpSchemas(["DATABASE"], "DATABASE");', and then load it into a new DB with mysqlsh --database=NEWDATABASE --execute 'util.loadDump("DATABASE", {dryRun: true, ignoreVersion:true});', but I instantly notice that it is trying to load into the original database, not my new database. So how do I load it into a NEW database, one with a totally different name?
In case you are wondering, I am trying to learn how to maximize mysqlsh for my use case. So the old mysqldump is not an option in this case.
I think you will just have to edit the .sql file(s) with a text editor before you try to load it.
This tool is really for dumping schemas and importing them to a different MySQL instance, but leaving the schema names unchanged.

Why do all my procedures run when I import mysqldump file?

I execute the following statement from the cmd terminal to import my MySQL Database:
mysql u- root p- database < "C:\Users\Tom\data.sql"
When I open my MySQL Database from the MySQL Workbench I've realised that more tables have been created that I don't recognise. Basically, what is happening is the stored procedures/routines I have created seem to be automatically running and thus creating many more tables? I don't want this, I'd rather execute routines as I wish using the "Call" statements in MySQL, is there a way stop this happening?

Facing issue in importing a large SQL dump

I have a SQL file with 22 MB(The Magento table - "index_event") , when i'm trying to import it to the MySQL database using MySQLWorkBench , WorkBench is not responding and hence i'm not able to import it.
Have tried to split the statements manually but few of the insert statements are very large and is hard to split as they were single statements.
Can anyone please suggest on how to tackle this situation?
Open a terminal and connect MySQL using below command.
mysql -u youruser -p
Now select your database in which you want to import schema and data.
use your_db_name;
Now Provide you sql file using below command.
source /home/user/yourdb.sql;

When I try to log into MySQL via command line, keeps saying "unknown database 'magento2'"

When I try to log into MySQL via command line, keeps saying "unknown database 'magento2'"
Any ideas why? Tried as my username and root, getting the same message. If I can't log into mysql, how could I create a database to begin with of that name? So confused.
You should separate between your database application and a logical database. MySQL server is your database application / server.
When you're logging on to MySQL, you're choosing which logical database you would like to work with. A logical database is actually a container of objects such as tables, triggers, views, etc.
So when you see the error unknown database X, it's because you installed the MySQL server, but didn't create the logical database.
To see a list of all logical databases in your server, login to MySQL and run the command show databases;
To create your database, run the command create database magento2;
Now when you login to that database, it should be there and you can start creating your tables and query data from them.
I had the same issue and found that the database name was set in a cnf file. Perhaps you have something similar.