Existing MySQL database is not importing to localhost - mysql

I am getting this error when I am trying to import my existing database to localhost. The database imports to web host servers but importing to the localhost.
The error is;
Static analysis:
2 errors were found during analysis.
Ending quote ' was expected. (near "" at position 28310)
4 values were expected, but found 3. (near "(" at position 28266)

PhpMyAdmin is kinda dumb since it cannot import what it itself exported. It escapes single quotes as '' instead of \' and then breaks its teeth on strings like this:
''I can''t do this anymore!''
You can either:
replace '' → \', or
import via mysql.exe:
mysql -uuser -ppass dbName < file.sql

open your .sql script file in any editor(like notepad++) and
You need to replace \'' with \' (for new version of phpmyadmin)
or
You need to replace \' with \'' (for old version of phpmyadmin)
when you will replace it from all content of sql file then
it will work for you.
ref:https://stackoverflow.com/a/41376791/2298211

This might happen because the database - size that you export is too big.
THE SOLUTION FOR ME WAS:
Choose from Export method:
Custom - display all possible options
Format: SQL
Output:
In Compression - choose the option zipped
export the database as zip , (ex: database_name.sql.zip)
import it on local, and from time to time if it throws an error for taking too long , you can resume the import, by press on resume and resubmit - and choose again the same database and will continue from where stopped before.
I attached a picture with these settings:

Related

Restore db from sql file

I am tring import data from sql file using command line like this:
mysys-12: mysql -u root -p my_db_t < my_db_t_2022_10_12.sql
but I got:
mysql: [ERROR] unknown variable 'sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTIO
How can I import data? Should I add any params?
It seems that the content in the sql file conflicts with the constraint of sql_mode. There are two methods. The first method is to modify the content of the file to meet the constraint of sql_mode. The second method is to set SQL _ mode ='' in mysql. Then import the data and change it back.
Problem solved, I removed sql-mode from client configuration, file: etc/mysql/conf.d/mysql.cnf
Server configuration - No change

DatabaseError: 1 (HY000): Can't create/write to file '2015-04-06 20:48:33.418000'.csv (Errcode: 13 - Permission denied)

I am designing an application in Python and trying to write to a CSV file, but I am getting this error:
DatabaseError: 1 (HY000): Can't create/write to file '2015-04-06 20:48:33.418000'.csv (Errcode: 13 - Permission denied)
The Code:
def generate_report(self):
conn=mysql.connector.connect(user='root',password='',host='localhost',database='mydatabase')
exe2 = conn.cursor()
exe2.execute("""SELECT tbl_site.Site_name, State_Code, Country_Code,Street_Address, instrum_start_date, instrum_end_date, Comment INTO OUTFILE %s FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n'FROM tbl_site JOIN tbl_site_monit_invent ON site_id = tbl_Site_site_id """, (str(datetime.datetime.now()),))
I can run this code without any errors on a Mac, but I need it to work on Windows.
How can I resolve this error?
Simple really. A colon character is not a valid character in a filename on Windows. It's not allowed.
Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
The colon character is in the list of "reserved characters", along with several others. (NOTE: One use of the colon character is as a separator for an Alternate Data Stream on NTFS. Ref: http://blogs.technet.com/b/askcore/archive/2013/03/24/alternate-data-streams-in-ntfs.aspx
Followup
The question has been significantly edited since my previous answer was provided. Some notes:
I'm not very familiar with running MySQL on Windows OS. Most of my work with MySQL server is on Linux.
The SELECT ... INTO OUTFILE statement will cause the MySQL server to attempt to write a file on the server host.
The MySQL user (the user logged in to MySQL) must have the FILE privilege in order to use the SELECT ... INTO OUTFILE statement.
Also, the OS account that is running MySQL server must have OS permissions to write a file to the specified directory, and the file to be written must not already exist. Also, the filename must conform to the naming rules for filenames on OS filesystem.
Ref: https://dev.mysql.com/doc/refman/5.5/en/select-into.html
For debugging this type of issue, I strongly recommend you echo out the actual SQL text that is going to be sent to the MySQL server. And then take that SQL text and run it from a different client, like the mysql command line client.
For debugging a privileges issues, you can use a much simpler statement. Test writing a file to a directory that is known to exist, that is known the mysql server has permissions to write files to, and with a filename that does not exist and that conforms to the rules for the OS and filesystem.
For example, on a normal Linux box, we could test with something like this:
mysql> SELECT 'bar' AS foo INTO OUTFILE '/tmp/mysql_foo.csv'
Before we run that, we can easily verify that the /tmp directory exists, that it is writable by the OS account that is running the mysql server, and that the filename conforms to the rules for the filesystem, and that the filename doesn't exist, e.g.
$ su - mysql
$ ls -l /tmp/mysql_foo.csv
$ echo "foo" >/tmp/mysql_foo.csv
$ cat /tmp/mysql_foo.csv
$ rm /tmp/mysql_foo.csv
$ ls -l /tmp/mysql_foo.csv
Once we get over that hurdle, we can move on to testing writing a file to a different directory, a file with a more more complex filename. Once we get that plumbing working, we can work on getting actual data, into a usable csv format.
The original question seems to indicate that the MySQL server is running on Windows OS, and it seems to indicate that the filename attempting to be written contains semicolon characters. Windows does not allow semicolon as part a filename.
It was simply permission error.

SOURCE error 2?

When i try to source an sql file i get the error:
mysql> source C:/Users/tom/Documents/insert.sql
ERROR:
Failed to open file 'C:/Users/tom/Documents/insert.sql', error: 2
I have checked the file path, which looks fine to me. I have also tried \. C:/Users/etc
I am trying to source the sql file which holds insert statements for particular tables. All the statements in the file work when entered manually. What else could i be doing wrong?
Have tried using both backslash and forward slash when using this command
Probably a problem of access right on the file (the file is being accessed by the mysqld server process, not yourself). Try placing the file into the data folder of MySQL, then import it from this location. The location of data folder depends on your distribution and on your own configuration.
Alternatively, feed the SQL script directly to your mysql client's stdin:
mysql [all relevant options] your_database < C:\path\to\your\script.sql
I am using Ubuntu 14.04 version.
I too faced below error 2.
mysql> SOURCE home/loc/Downloads/AllTables.sql;
Failed to open file 'home/loc/Downloads/AllTables.sql', error: 2
Solution :
mysql> SOURCE /home/loc/Downloads/AllTables.sql;
Just added a '/' in front of home
Hope this helps some one.
Have you checked if the file exits? I have had this problem before.
This:
this:
and this works:

Importing csv file cyrillic characters to Mysql - PHPMyadmin

Hello hard question here,
I am trying to import a csv file with cyrillic characters such as (RUSSIAN cities, they may be over 40.000) - This is displayed in the notepad++ editor with the encoding set to UTF-8 without bom -:
RU,101000,Москва,Москва,,,,,,55.7522,37.6156,4
RU,101194,Москва 194,Москва,,,,,,55.7522,37.6156,1
RU,101300,Москва 300,Москва,,,,,,55.7522,37.6156,1
and then I import it using the import tab in phpmyadmin.
once when I browse the data imported. I have the following characters:
RU 101000 МоÑква МоÑква
RU 101194 МоÑква 194 МоÑква
RU 101300 МоÑква 300 МоÑква
I've already set up the database to utf8_general_ci, I tried utf8_unicode_ci and utf8_lithuanian_ci... I do not know what to do to force an utf8 display in the phpmyadmin panel.
Is there a solution to import the data trhogh with a SQL input?
Thanks in advance!!
It looks like the problem is related to the connection pipe phpMyAdmin is using to connect to the MySQL server.
According to this solution, phpMyAdmin uses cpg_db_connect() to connect to your db server and it needs to be updated to include SET NAMES 'utf8'. They give the following example:
function cpg_db_connect()
{
global $CONFIG;
$result = #mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);
if (!$result) {
return false;
}
if (!mysql_select_db($CONFIG['dbname']))
return false;
mysql_query("SET NAMES 'utf8'", $result); # <-- see here
return $result;
}
If you cannot edit your phpMyAdmin install (say you're on a shared server), just install phpMyAdmin on your own site in a virtual/subdirectory and then find and edit this function. phpMyAdmin is just a php site like any other.
The purer way to do this (especially if you have character concerns) would be to import the data over ssh using mysql (e.g. mysql -u dbuser -p dbname < import.sql).

.db file and MySQL

I am having real issues with a .db file its around 20gb in size with three tables and the rest data.
I am on a mac so i am having to use some crappy apps but it wont open in Access.
Does any one know what software will produce a .db file and what software will allow me to open it and export it as a CSV or MySQL file ?
Also if the connection was interrupted during transit could this effect the file ?
Since mac is BSD-based now, try opening a terminal and executing the command file /path/to/large/db -- it should tell you at least what file type the DB is, and from there you can determine what program to use to open it. It might be MySQL, might be PostGreSQL, might be SQLite -- file will tell you.
Example:
$ file a.db
a.db: SQLite 3.x database
$ file ~/.kde/share/apps/amarok/mysqle/amarok/tracks.{frm,MYD,MYI}
~/.kde/share/apps/amarok/mysqle/amarok/tracks.frm: MySQL table definition file Version 10
~/.kde/share/apps/amarok/mysqle/amarok/tracks.MYD: data
~/.kde/share/apps/amarok/mysqle/amarok/tracks.MYI: MySQL MISAM compressed data file Version 1
So it's SQLite v3? Then try
sqlite3 /path/to/db
and you can perform pretty much standard SQL from the CLI. At the CLI, you can type .tables to list all the tables in that DB. -- Or if you prefer a GUI, there are a few options listed in this question. Accepted answer was SQLite manager for Firefox.
Then you could drop tables or delete as you see fit.
Here's an example of dumping a csv to stdout:
$ sqlite3 -separator ',' -list a.db "SELECT * FROM t"
3,4
3,5
100,200
And to store it to a file -- the > operator redirects output to a file you name:
$ sqlite3 -separator ',' -list a.db "SELECT * FROM t" > a.csv
$ cat a.csv # puts the contents of a.csv on stdout
3,4
3,5
100,200
-separator ',' indicates that fields should be delimited by a comma; -list means to put row data on the same line, using the delimiter; a.db indicates which db to use; and "SELECT * FROM t" is just the SQL command to execute.
I'm not a Mac user but if it's a SQLite file I've heard great things about Base.