How to restore dump file using Mysql Query Browser - mysql

When i am trying to run some queries from the batch file i am getting some error message in my query browser
I have tried with
source E:\Rename_scripts_unused_tables_msp.sql
and i am getting error message like
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 'source E:\Rename_scripts_unused_tables_msp updated.sql' at line 1'
And the query works fine in command line.
Here is my source file statements:
rename table appliance_backup_usage_history to unused_appliance_backup_usage_history;
rename table backup_core_server to unused_backup_core_server;
rename table bdr_vms to unused_bdr_vms;
rename table client_details1 to unused_client_details1;
rename table client_service_technologies_backup to unused_client_service_technologies_backup;
rename table cloud_instances to unused_cloud_instances;
and more statements like that
What's the reason behind this ??

source is a mysql CLI command - not an SQL query command. It only works using the command line client mysql.
https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html

Related

Error during importing a mysql database from 5.6.34 to 5.7.x

I am importing a .sql file using MySQL WorkBench but getting an error for syntax. The sql file was obtained from a DB running 5.6.34 and new one is running 5.7.2.09.1. Here is the screenshot of the error.
ERROR 1064 (42000) at line 11347: 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 'DEFINER=`psx360`#`localhost` SQL SECURITY DEFINER */
Open the .sql file with your code editor such as vscode, then search and replace (like press CTRL + H) DEFINER=psx360#localhost SQL SECURITY DEFINER with blank value in the replace textbox. ie deleting all the occurence.

Error code: 1064 in MySQL when create SOURCE?

I want to use my SQL'book_data2' file from the desktop E drive as a 'SOURCE'. But I am getting an error code 1064 in MySQL workbench. Could you help me for that issue? I am giving the code and action output below.
Code:
SOURCE E:\DataPractice\Practice\book_data2.sql;
Action Output:
Error Code: 1064. 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 'SOURCE E:\DataPractice\Practice\book_data2.sql' at
line 1 0.000 sec
There are a number of commands that are supported by the mysql client (that is, the command-line client, not MySQL Workbench), but they are parsed in the client, not sent to the server as SQL statements. The MySQL Server does not recognize these commands.
It can be confusing, but remember both the client and the server may process commands. You just have to read the documentation to learn which commands are in the list of client-only commands:
https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
(Except USE, which is recognized by both mysql client and server, just to make sure there's an exception to every rule!)
If you want to use MySQL Workbench to "source" an SQL file, in other words load a file, read the SQL commands in that file, and execute them, Workbench does support this action, but they call it Data Import/Restore. It's documented here: https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html

Error when SQL query called from C program

I want to execute SOURCE data/keyw.sql from C program. This query works fine when I execute from the command line but gives the following error on executing mysql_query(con, "SOURCE data/keyw.sql")
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 'SOURCE data/keyw.sql' at line 1
Any help would be highly appreciated.
The SOURCE command is not executed on the MySQL server. It is interpreted by the mysql Client, and is basically just a convenience.
Quote from MySQL documentation:
mysql sends each SQL statement that you issue to the server to be executed. There is also a set of commands that mysql itself interprets. For a list of these commands, type help or \h at the mysql> prompt:
Note that source is one of those listed. If you want to know how it works, then have a look at the source code for the mysql Client.
If your source to be executed contains more than one MySQL statement then your connection will need to support multiple statement execution, or alternatively you need to parse the SQL into individual statements yourself.

Is there a way to run multi-SQLs by RMySQL(dbExecute)?

I am using RMySQL to connect and manipulate MySQL.
Now I have a SQL like:
"drop table if exists t_tmp; create table t_tmp(name varchar(20));"
which works just fine in MySQL CLI.
But when I put these SQLs to RMySQL.dbExecute() exception throws:
"could not run statement: 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 'create table t_tmp(name varchar(20))' at line 1"
I am trying to run the 2 SQLs respectively, then they both work out OK.
Is there any way I can put the whole STRING(SQLs) and run it correctly in RMySQL?
Thanks!

Import multiple large sql dump mysql

I want to import several .sql files into database using source command (mysql command line). But when I get this error:
source E:\Progs\Backups\DBs\file01.sql
ERROR:
Unknown command '\P'.
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 'sourc
e E:\Progs' at line 1
....
I used source command to import large files hundreds times but now I can not understand what I'm doing wrong. This is my system(I'm using XAMPP (Basis Package) version 1.7.3 :
Windows 7x64
MySQL 5.1.41 (Community Server) with PBXT engine 1.0.09-rc
Any help would be appreciated.
Thanks!
Edit:
I tried this one, but same error:
source 'E:\Progs\Backups\DBs\file01.sql'
MySQL sees the \P in E:\Progs as a command. Because that command does not exist, it complains.
Forward slashes are understood in many cases. Try:
source E:/Progs/Backups/DBs/file01.sql