I am using erlang odbc module to connect to mysql and it is working fine for almost all my commands like insert,delete,create,use,drop . But here i need to use the source command to load a file which contain all the commands like create and use database and create some 10 tables... but when i use it like odbc:sql_query(Database_Connection,"source filename") i am getting error and getting disconnected. The file is present in the current directory, i tried giving both the absolute and relative path to the file. PLease do suggest how to use the source command in erlang odbc.
there is no such 'source' sql command in mysql.
There is 'source' command in the mysql shell utlility. But it's just a command for mysql shell (to read and send sql commands to server).
'source' is MySQL CLI command rather than SQL one. I haven't used erlang ODBC personally, but I had similar problem when using JDBC. As far as I remember there was no other option but reading the SQL script, splitting it into separate statements and running them separately one by one.
Related
I am getting an error while running a SQL script to load data. Error is pasted below:
Preparing...
[WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\PRATIK~1\\AppData\\Local\\Temp\\tmpf75l0wi5.cnf'
I have tried uninstalling and installing MySQL several times but nothing is helping.
I faced the same issues while trying to run a MySQL script. I tried to find the process in the temp folder and removed it and tried again but the process seems to start again and appears in the temp folder. I could not run the script, however, I found a workaround, instead of running the script try to open it and run it in the query editor.
Just downgrade your MySQL workbench version.
In my case I downgraded the version from
8.0.25 to 8.0.20.
The sounds like you already had tried that script execution before and stopped it without stopping the mysqld process. So this process (which does the actual import) still holds a file lock on the temporary config file.
Try removing that file and check that all MySQL processes that you don't want are stopped. Then try again.
It seems the actual issue is not related to MySQL itself, but to MySQL Workbench.
The error you're seeing is a generic error coming from Windows itself, not from MySQL. It's unclear how you're running MySQL, for example is it in your localhost, in a Docker environment, or in a remote server.
It seems clear that at least two processes are trying to get an exclusive lock on that temporary file. My guess is that MySQL won't write temporary files to the user folder we're seeing (with your username Pratik).
On Windows, MySQL checks in order the values of the TMPDIR, TEMP, and TMP environment variables. For the first one found to be set, MySQL uses it and does not check those remaining. If none of TMPDIR, TEMP, or TMP are set, MySQL uses the Windows system default, which is usually C:\windows\temp.
Something you can do is to change your MySQL configuration so it uses a specific Temporary path you'll set, restart MySQL and retry running the query. If you see the error contains your new temporary path you've isolated the issue, it is indeed a MySQL problem. If you keep seeing this path you've isolated the issue to MySQL WorkBench.
An alternative approach would be to run the same query from another MySQL client, for example the command-line client mysql; and see if you're getting the same error.
Probably the simpler approach would be to try the queries with dBeaver, another MySQL client, and use that to isolate the issue to either the MySQL server itself or MySQL WorkBench.
This is a common issue for the upgraded version of MySQL, Try using Open Script instead of Run Script and that seems to clear up the issue.
I've found that it was already reported in the official bug tracker: https://bugs.mysql.com/bug.php?id=104841.
I've just checked, and it's still present in MySQL Workbench 8.0.30.
Work Around
Do not try to open the SQL file from this tool bar:
Go to Server > Data Import:
select import from self-contained file
select your target schema
then start import (bottom right btn)
I wanted to know how I can run a .sql file which contains several queries in powershell
What I need is that through the command console of powershell, execute this .sql file and start creating the db with its respective tables from the querys that has this file, I understand that in linux I can do it, but I would like to know how to do it in powershell
from now on thanks
The powershell command looks like this
C:\> cmd.exe /c "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe -u root -p password ]schema_name} < DataBase72.sql"
there are more Options for mysql.exe
Without getting into the specifics, there are two general ways to do this:
Remember there's a reason it's named PowerShell: it's also a full command line shell. This means you can connect to MySql the same way as in other shells, using the same tools provided by the database (ie: mysql.exe, mysql-cli, etc)
Powershell can use .Net libraries, including the same .Net libraries used for connecting to MySql from a C# or VB.Net program. If Connector/Net is available on the system, or if you can install it for the version of .Net available to you, you can create and use these ADO.Net objects from PowerShell code.
I am using MYSQL Workbench and I want to clone a database on the same server with different name. It should duplicate the all the tables structure and data into the new database.
I know the usual way is probably using data export to generate a sql script of the database and then run the script on the new database but I encounter some issues with it.
Anyway, is there any better way or easier way to do so?
You can use migration wizard from MySQL Workbench. Just choose the same local connection in both source and target selection, then change schema name on manual editing step. If nothing appears on manual editing step click next and the source and targets will appear. Click slowly on the source database name and edit to the correct name. Go thorough to the end and voilà - you have two identical databases with different names. Note you must have created the target database already and granted permissions to it for the MySQL Workbench user.
I tried to do it in MySQL Workbench 8.0. However I kept receiving an error regarding column-statics. The main idea is to use mysqldump.exe, located in the installation directory of MySQL Workbench, to export the data. So, supposing a Windows oriented platform:
Open Powershell, navigate to mysqldump.exe directory. In my case the command is:
cd C:\Program Files\MySQL\MySQL Workbench 8.0 CE
Export database by executing mysqldump providing the right arguments:
./mysqldump.exe --host=[hostServerIP] --protocol=tcp --user=[nameOfUser] --password=[yourPassword] --dump-date=FALSE --disable-keys=FALSE --port=[portOfMysqlServer] --default-character-set=utf8 --skip-triggers --column-statistics=0 "[databaseName]"
Without changing directory, import the exported file (.sql) by using the following command in Powershell:
Get-Content "[pathToExportedDataFile]" | ./mysql.exe --user=[nameOfUser] --password=[yourPassword] --port=[portOfMysqlServer] --host=[hostServerIP] --database=[nameOfNewDatabase] --binary-mode=1
You can check in the documentation here for more information regarding the mysqldump options.
Please note the following:
Do not forget to replace the values in [] with your own values and remove the []. Do not remove the quotes("") where the are present.
Do not switch Powershell for cmd or something like git-bash, since the above will not work.
As far as step 3 is concerned, I created the new database from MySQL Workbench and then ran the powershell command.
List item First, create a new database using CREATE DATABASE statement.
Second, export all the database objects and data of the database from which you want to copy using mysqldump tool.
Third, import the SQL dump file into the new database.
I have MySQL 5.7 Community installed on Win10 and I have been using it with MySQL Workbench. Now I want to set up a replication slave and from what I found this is not possible using Workbench.
That means I have to use the Shell. According to the MySQL docs I open the Windows PowerShell (as I understand “your command interpreter”) and type the name of my database.
so the line in the PowerShell looks like this:
PS C:> mysql my_database
What I get is: “mysql: the name ‘mysql’ was not recognized as the name of a Cmdlet, a function …” (this is my translation). I tried it with the path to where MySQL is installed but same output. Where is my mistake? What is missing? Would be happy if someone could give me a hint! Thanks!
You need to set mysql in your windows environment variables to use the command "mysql" in your terminal. You could also use the full path in your terminal, but it's annoying and bad for scripting
I have a single table with 600,000 rows that I would like to migrate to MySQL.
I'm on Linux so I can't use the Microsoft SQL server GUI.
The MS SQL server instance is running inside a Docker container on my local machine and I'm using sqlcmd as the client shell.
So far I tried exporting the table to a CSV and then importing it inside MySQL but it seems like that isn't as easy as I thought.
These are some of the problems I encountered:
I couldn't find a way to export the table schema so I had to copy it manually.
Exported CSV has empty fields ,, and MySQL produces an error when importing since it doesn't automatically recognise them as NULL.
Strings are not enclosed in quotes '' and produce an error.
Is there an easier way of doing this?
P.S. I'm aware that there are similar questions already asked but none of them have good answers and most of them assume access to the Microsoft SQL server GUI application.