mysql import trouble using XAMP - mysql

originally i was using easyPHP (windows) then i switch to mac and used MAMP.
i archive my db every once in a while and right before i reformatted. The export was made by going into the root of phpMyAdmin and using the export function. Now i am trying to import the data i get this error "#1044 - Access denied for user 'root'#'localhost' to database 'information_schema'". Doing other things i got errors like
"#1146 - Table 'test_db.COLLATION_CHARACTER_SET_APPLICABILITY' doesn't exist", "#1146 - Table 'test_db.CHARACTER_SETS' doesn't exist " and "#1146 - Table 'test_db.COLUMNS' doesn't exist" and "#1046 - No database selected"
How do i get MAMP to import and ignore any access errors and continue so my DB is filled to the previous state? I rather not write an app to do this but if i had to what libs would i use to parse the sql statements in the sql dump? It doesnt look hard to parse. It looks like a semicolon separates the statements. But what about escape and unescape issues? how do i handle that?

The first error indicates that something is very wrong with your setup. information_schema is an internal DB which keeps data about other parts of the system (meta-data). You should try reinstalling your MySQL server (or even MAMP as a whole).
Second of all: the dump files can be imported using the mysql command line client like this:
mysql -p -u root test_db < dump.sql
One thing to remember is that "test_db" needs to be created before the dump is restored. An other possible problem might be that the dump/restore is being done by different versions of MySQL (ie. 5.0 vs 5.1). For this you could try the --force command in the mysql command line to skip over failed executions, however be aware that this might not correctly restore your data.

Related

MySQL Workbench - How to clone a database on the same server with different name?

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.

ERROR 1193 (HY000): Unknown system variable 'GTID_PURGED'

I took backup of database from workbench from a remote server. So when I import it on my local environment I got error:
ERROR 1193 (HY000): Unknown system variable 'GTID_PURGED'
I'm using xampp server
Getting same error either import db via console or phpmyadmin
Need remove all lines with GTID_PURGED
sed -i '/##GLOBAL.GTID_PURGED=/d' your_file.sql
The final file will load without problems
After spending a lot of time.
I opened my database file in text editor and search for this variable "GLOBAL.GTID_PURGED". I just set it's value ""
like
SET ##GLOBAL.GTID_PURGED=""
Then I upload database via windows console now It works like a charm :)
Re-create the dump file by appending the --set-gtid-purged=OFF option would resolve the problem.
It was because GTIDs was added in MySQL 5.6, which is not recognized by the earlier versions.
Your command might look like below:
mysqldump -u username -ppassword -h mydbhost --set-gtid-purged=OFF db_name > dump_file.sql
More on my story, I got the same problem with a dump file originated from MySQL 5.7. I was trying the import the data into a new CentOS 7 installation with the default MariaDB installation, which is 5.5 (I guess).
The first idea came to my mind was to upgrade to latest MariaDB. Luckily their website provides a great utility to help set the package repository for Linux variaties. Moreover, digitalocean has a very short and clear guide for the upgrade process, thanks to them too!
While upgrading to the lastest MariaDB stable version 10.2 does NOT get rid of this problem. So I still have to use the option mentioned above, but it let me upgrade to the latest MariaDB anyway.
Another problem after my upgrading was that the innodb_additional_mem_pool_size config from my-innodb-heavy-4G.cnf is not supported anymore on the latest MariaDB, server failed to start. From the MySQL documentation, it was removed from MySQL 5.7. I can start the server after commenting it out. I'm not the DB expert, I would not spend more time to check how exactly MariaDB version mapping to MySQL DB, and what difference they have.
Kindly follow below step to resolve this.
Open your DB dump in notepad++/notepad
Search for SET ##GLOBAL.GTID_PURGED="[some value will be here]"
Just remove this [SET ##GLOBAL.GTID_PURGED=""] line from the db dump
Save your DB dump and try to import now.
This is working for me and I hope this will work for you as well .
You can also set the set-gtid-purged=OFF from MySQL workbench, before running the dump, click on advance options and change the AUTO to OFF under set-gtid-purged. run the dump and there should be no problem restoring to a different MySQL version.
It may be tricky to load the file and edit it if this is a large database. Here is how I did it:
I located the line number with less -N dump.sql. It was at line 24.
Then I commented that line with sed -i '24s/SET/\#SET/' dump.sql.
Finally, the mysql command to import the database dump worked.

Accessing different databases via command line than phpmyadmin

I 've re-installed mysql, uninstalled MAMP.
So currently I should only have one version of mysql.
I've done the following:
Installed phpmyadmin
Created a database
I try to import data to it, but the file is too big so I do it via the command line. But there I dont see my newly created database, furthermore I see less databases.
If I do show databases; on the command it shows:
information_schema
test
It doesnt show my newly created Database and it doesn`t show other databases that were pre-installed, these are the databases that I see on phpmyadmin:
information_schema
mysql
performance_schema
test
myBBDD->the one I just created and I was looking for to import data via command-line
It seems I have two versions of mysql, but if I stop mysql via command line, I then can't access phpmyadmin so I guess it's the same one, but for some reason I can't access the same databases.
If you could throw me a bone on this? Im completely lost.
To install mysql and phpmyadmin I've followed this tutorial
[EDIT]
I tried to delete test and it did dissapear from the command-line too, so it is the same version of MySql, so it must be a permission issue... still investigating
Thanks.
Sounds like you have MAMP's version of MySQL and a standalone MySQL. See this answer:
Access MAMP's MySQL from Terminal
Just had the same issue, in my case it turned out to be that I wasn't logging in as the correct user.
In the command line, instead of running just mysql, try running mysql -u root -p (replace "root" with whatever user you used in phpMyAdmin to set the databases up). You should then be able to type in the password. Check show databases; again.
Just noticed that user Grasshopper in a previous answers' comments was suggesting exactly this, hopefully this will help someone anyway by spelling it out.

How do I export a MySQL database from PHPMyAdmin and import it to SQLite?

I would like to export a database from PHPMyAdmin (or MySQl Workbench) and import it to a SQLite database so that I can do local editing and testing without screwing up the live version. I am very new to SQL, so all of the export options, etc, are rather dense to me at this point. I have tried using the default export settings PHPMyAdmin with the command
sqlite3 test_db.db < maindb.sql
as well as
sqlite3--> .read maindb.sql
But these throw a bunch of syntax errors and 'no such table' errors.
I have also tried the oft-cited script script found here, but when I try to run this using an export from MySQL Workbench, using the command:
943776/mysql2sqlite.sh maindb.sql | sqlite3 test_db.sqlite
I get the following error:
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2) when trying to connect
Am I not configuring the exports correctly?
Please see that the referenced script connects to the database server itself. It does not expect a dump!
./mysql2sqlite -h example.com -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
This is the way the script should be executed. With host, username, passwort and the mysql database you would like to dump.
Since database dumps and DBMS features can be severely different between different DBMS (like MySQL and sqlite3), I would recommend to install a local MySQL server instead of using sqlite3. What advantage have you achieved when you make changes to sqlite3, which you cannot apply to the MySQL production database without changes?
An alternative solution is to export an sql dump of your database and then import it back into phpLiteAdmin. From there you can manage your sqlite database inside your browser. When you want to export it, just open the folder where the database is stored and copy the database file.
This solution does not require messing around with scripts, and it's especially handy if you're on a Mac and you're using MAMP, since phpLiteAdmin comes preinstalled with it.

cannot upload large .sql database file to newly installed mysql using mysqldump in windows 7 <new mysql user>

I've checked through tons of forums and cannot seem to fix this. I need to upload a large database dump file (.sql) to mysql so that I can begin using the database as a key component of a website build project. I've tried various methods and I've been unsuccessful with all. First I tried to upload via phpmyadmin with no avail (it seems the file is too big). So I downloaded mysql and have begun learning cmd prompts (before I did that I tried to import from disk and from Dump Project Folder in MySQL Workbench - I received errors no matter where I put the file, e.g. in the MySQL Server 5.5\bin folder or the folder where I originally had it C:\Program Files\my project\test.sql - errors included "ERROR 1046 (3D000) at line 22: No database selected"). Regarding command prompts, I've set up MySQL in environment variables path and when I enter:
mysql> source c:/program files/mysql/mysql server 5.5/bin/test.sql
The cmd freaks out and starts producing lines and lines of ERROR 1046 (...) then after a few minutes of producing lines it says Query OK, 0 rows affected <0.00 sec> for about 10 lines then returns to the "mysql>" prompt. I thought the fact that my file began with "g" may have been the problem so I changed it to start with "t" and it did the same thing. That seems to be the closest I've managed to come to accessing this file. I've been trying for months now. I really need to get into this file and I'm at a loss. Can someone please help??
You need to select a database, as your error says. I have no clue what your .sql file says, and why there is no "use DATABASE" string in there, but
Check if you have made a database (show databases;)
If not made, make a database. (http://dev.mysql.com/doc/refman/5.0/en/create-database.html )
use the database with use databasename
load your script.
Login to MySQL and create a new database, say "mydatabase". Then run the following query on the command prompt (not inside MySQL)
mysql -u root -p mydatabase < my_large_db_dump.sql